Skip to content

Force show methods for FileLogger #46

@IanButterworth

Description

@IanButterworth

Is there a way to force show methods to run for the FileLogger, so that both console and file outputs look similar?

julia> using LoggingExtras

julia> rotating_logger = DatetimeRotatingFileLogger(@__DIR__, raw"\L\C-YYYY-mm-dd.\l\o\g");

julia> tlog = TeeLogger(rotating_logger, global_logger());

julia> with_logger(tlog) do
           try
               error("This broke")
           catch e
               @error "Something broke" exception=(e, catch_backtrace())
           end
       end
┌ Error: Something broke
│   exception =
│    This broke
│    Stacktrace:
│      [1] error(s::String)
│        @ Base ./error.jl:33
│      [2] (::var"#5#6")()
│        @ Main ./REPL[12]:3
│      [3] with_logstate(f::Function, logstate::Any)
│        @ Base.CoreLogging ./logging.jl:491
│      [4] with_logger(f::Function, logger::TeeLogger{Tuple{DatetimeRotatingFileLogger, ConsoleLogger}})
│        @ Base.CoreLogging ./logging.jl:603
│      [5] top-level scope
│        @ REPL[12]:1
│      [6] eval
│        @ ./boot.jl:369 [inlined]
│      [7] eval_user_input(ast::Any, backend::REPL.REPLBackend)
│        @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:139
│      [8] repl_backend_loop(backend::REPL.REPLBackend)
│        @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:200
│      [9] start_repl_backend(backend::REPL.REPLBackend, consumer::Any)
│        @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:185
│     [10] run_repl(repl::REPL.AbstractREPL, consumer::Any; backend_on_current_task::Bool)
│        @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:317
│     [11] run_repl(repl::REPL.AbstractREPL, consumer::Any)
│        @ REPL /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:305
│     [12] (::Base.var"#914#916"{Bool, Bool, Bool})(REPL::Module)
│        @ Base ./client.jl:394
│     [13] #invokelatest#2
│        @ ./essentials.jl:721 [inlined]
│     [14] invokelatest
│        @ ./essentials.jl:719 [inlined]
│     [15] run_main_repl(interactive::Bool, quiet::Bool, banner::Bool, history_file::Bool, color_set::Bool)
│        @ Base ./client.jl:379
│     [16] exec_options(opts::Base.JLOptions)
│        @ Base ./client.jl:309
│     [17] _start()
│        @ Base ./client.jl:492
└ @ Main REPL[12]:5

Contents of the log file:

┌ Error: Something broke
│   exception = (ErrorException("This broke"), Union{Ptr{Nothing}, Base.InterpreterIP}[Ptr{Nothing} @0x000000011689edce, Ptr{Nothing} @0x00000001156ec129, Ptr{Nothing} @0x00000001156ec15c, Ptr{Nothing} @0x00000001081c0faf, Ptr{Nothing} @0x000000011665d598, Ptr{Nothing} @0x00000001156cfce8, Ptr{Nothing} @0x00000001156cfd68, Ptr{Nothing} @0x00000001081c0faf, Ptr{Nothing} @0x00000001081d8caf, Ptr{Nothing} @0x00000001081d72a4, Ptr{Nothing} @0x00000001081d787c, Base.InterpreterIP in top-level CodeInfo for Main at statement 7, Ptr{Nothing} @0x00000001081f271f, Ptr{Nothing} @0x00000001081f24bc, Ptr{Nothing} @0x00000001081f24bc, Ptr{Nothing} @0x00000001081f3004, Ptr{Nothing} @0x0000000116b44224, Ptr{Nothing} @0x0000000116b447b3, Ptr{Nothing} @0x000000011662077c, Ptr{Nothing} @0x0000000116657674, Ptr{Nothing} @0x0000000116657738, Ptr{Nothing} @0x00000001081c0faf, Ptr{Nothing} @0x000000011640cbaf, Ptr{Nothing} @0x000000011640cc48, Ptr{Nothing} @0x00000001081c0faf, Ptr{Nothing} @0x00000001081cdc09, Ptr{Nothing} @0x00000001169971c5, Ptr{Nothing} @0x00000001169a11a3, Ptr{Nothing} @0x0000000116361a4a, Ptr{Nothing} @0x0000000116361ba5, Ptr{Nothing} @0x00000001081c0faf, Ptr{Nothing} @0x00000001082125c2, Ptr{Nothing} @0x00000001082124b3])
└ @ Main REPL[12]:5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions