invenia / Memento.jl

A flexible logging library for Julia
https://invenia.github.io/Memento.jl/latest
Other
87 stars 14 forks source link

`@test_log` hides all logs event when exceptions occur #158

Open omus opened 4 years ago

omus commented 4 years ago

When using @test_log if an exception occurs you won't be able to see any Memento logs that may be helpful in determining the source of the error. For example:

julia> using Memento, Memento.TestUtils
julia> logger = getlogger()
Logger(root)
julia> @test_log logger "info" "test message" begin
           info(logger, "test message")
           warn(logger, "critical information")
           error("a problem occurred")
       end
ERROR: a problem occurred
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] macro expansion at ./REPL[3]:4 [inlined]
 [3] (::var"#3#4")() at /Users/omus/.julia/packages/Memento/UgJr2/src/memento_test.jl:35
 [4] setpropagating!(::var"#3#4", ::Logger, ::Bool) at /Users/omus/.julia/packages/Memento/UgJr2/src/loggers.jl:113
 [5] top-level scope at /Users/omus/.julia/packages/Memento/UgJr2/src/memento_test.jl:34
rofinn commented 4 years ago

The alternative would likely result in noisy tests.

omus commented 4 years ago

I was thinking of displaying all logs that occurred within the @test_log macro if an exception occurred. This would be a bit tricky as you'd need to capture the logs and emit them later which would be out of sync with anything printed directly to stdout.