Closed rofinn closed 4 years ago
I like it, no notes from me for the first WIP commit
A problem with this approach is that substituting the base logger won't do what we want for @warn
julia> using Memento
julia> Memento.config!("info"; substitute=true)
[notice | Memento]: Substituting global logging with Memento
Logger(root)
julia> push!(getlogger(), Escalator())
Escalator{DefaultFormatter}(DefaultFormatter("[{level} | {name}]: {msg}", Pair{Symbol,Bool}[Symbol("[") => 0, :level => 1, Symbol(" ") => 0, :| => 0, Symbol(" ") => 0, :name => 1, Symbol("]") => 0, :(:) => 0, Symbol(" ") => 0, :msg => 1], tz"America/Winnipeg"), Memento.Filter[Memento.Filter(Memento.var"#level_filter#27"{Escalator{DefaultFormatter}}(Escalator{DefaultFormatter}(#= circular reference @-4 =#)))], Dict{AbstractString,Int64}("trace" => 5,"critical" => 60,"error" => 50,"not_set" => 0,"notice" => 30,"alert" => 70,"info" => 20,"warn" => 40,"debug" => 10,"emergency" => 80…), "warn")
julia> @info "Hello World!"
[info | Main]: Hello World!
julia> @warn "Hello World!"
Exception handling log message: Memento.EscalationError("[warn | Main]: Hello World!")
module=Main file=REPL[8] line=1
Second exception: Memento.EscalationError("[error | Main]: Exception while generating log record in module Main at REPL[8]:1")
I think this is still better than nothing, but I'm not sure how to get around that without special casing the base logging behaviour.
Maybe this needs to be a settable option on a logger instead? So that way it can be handled in log
?
Figured it out. Turns out I needed to add:
CoreLogging.catch_exceptions(logger::BaseLogger) = false
I suppose in the future we could do something similar for the Memento loggers, but for now that does what we want.
julia> using Memento
[ Info: Precompiling Memento [f28f55f0-a522-5efc-85c2-fe41dfb9b2d9]
julia> Memento.config!("info"; substitute=true)
[notice | Memento]: Substituting global logging with Memento
Logger(root)
julia> push!(getlogger(), Escalator())
Escalator{DefaultFormatter}(DefaultFormatter("[{level} | {name}]: {msg}", Pair{Symbol,Bool}[Symbol("[") => 0, :level => 1, Symbol(" ") => 0, :| => 0, Symbol(" ") => 0, :name => 1, Symbol("]") => 0, :(:) => 0, Symbol(" ") => 0, :msg => 1], tz"America/Winnipeg"), Memento.Filter[Memento.Filter(Memento.var"#level_filter#27"{Escalator{DefaultFormatter}}(Escalator{DefaultFormatter}(#= circular reference @-4 =#)))], Dict{AbstractString,Int64}("trace" => 5,"critical" => 60,"error" => 50,"not_set" => 0,"notice" => 30,"alert" => 70,"info" => 20,"warn" => 40,"debug" => 10,"emergency" => 80…), "warn")
julia> @warn "Hello World!"
ERROR: Memento.EscalationError("[warn | Main]: Hello World!")
Stacktrace:
[1] emit(::Escalator{DefaultFormatter}, ::DefaultRecord) at /Users/rory/repos/invenia/Memento.jl/src/handlers.jl:270
[2] log(::Escalator{DefaultFormatter}, ::DefaultRecord) at /Users/rory/repos/invenia/Memento.jl/src/handlers.jl:44
[3] log(::Logger, ::DefaultRecord) at /Users/rory/repos/invenia/Memento.jl/src/loggers.jl:362
[4] #handle_message#70(::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(Base.CoreLogging.handle_message), ::Memento.BaseLogger, ::Base.CoreLogging.LogLevel, ::String, ::Module, ::String, ::Symbol, ::String, ::Int64) at /Users/rory/repos/invenia/Memento.jl/src/stdlib.jl:31
[5] handle_message(::Memento.BaseLogger, ::Base.CoreLogging.LogLevel, ::String, ::Module, ::String, ::Symbol, ::String, ::Int64) at /Users/rory/repos/invenia/Memento.jl/src/stdlib.jl:29
[6] top-level scope at logging.jl:320
Merging #156 into master will increase coverage by
1.04%
. The diff coverage is92.3%
.
@@ Coverage Diff @@
## master #156 +/- ##
==========================================
+ Coverage 96.51% 97.56% +1.04%
==========================================
Files 12 12
Lines 316 329 +13
==========================================
+ Hits 305 321 +16
+ Misses 11 8 -3
Impacted Files | Coverage Δ | |
---|---|---|
src/Memento.jl | 100% <ø> (ø) |
:arrow_up: |
src/stdlib.jl | 77.77% <0%> (+40.27%) |
:arrow_up: |
src/handlers.jl | 100% <100%> (ø) |
:arrow_up: |
src/exceptions.jl | 66.66% <100%> (+16.66%) |
:arrow_up: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update 1d0e95c...3ab8621. Read the comment docs.
Closes #155