invenia/Memento.jl

"stacktrace" and "lookup" fields for DefaultRecord don't work

Closed this issue · 2 comments

I'm not sure they ever did.

julia [mementotalk]> Memento.config!("info"; fmt="{stacktrace}")
Logger(root)

julia [mementotalk]> info(getlogger("root"), "ding")
 stack:[_collect@array.jl:483, format@formatters.jl:55]

julia [mementotalk]> function foo(x)
                         info(getlogger("root"), x)
                     end
foo (generic function with 1 method)

julia [mementotalk]> foo("bar")
 stack:[_collect@array.jl:483, format@formatters.jl:55]

Looks like this may have been broken when I introduced the lazy record evaluation and Attribute code. I haven't checked, but we may have stopped explicitly testing the stacktrace output because that interface changed significantly between 0.5 and 0.6.

NOTE: If I evaluate the Attributes ahead of time by putting println(Dict(rec)) before the format call in the emit(::DefaultHandler, ...) call I get different stacktrace output.

julia> using Memento
INFO: Recompiling stale cache file /Users/rory/.julia/lib/v0.6/Memento.ji for module Memento.

julia> Memento.config("info"; fmt="{stacktrace}")
Logger(root)

julia> info(getlogger("root"), "ding")
Dict{Symbol,Any}(Pair{Symbol,Any}(:level, "info"),Pair{Symbol,Any}(:msg, "ding"),Pair{Symbol,Any}(:name, "root"),Pair{Symbol,Any}(:levelnum, 20),Pair{Symbol,Any}(:lookup, collect_to!(::Array{Pair{Symbol,_} where _,1}, ::Base.Generator{Array{Symbol,1},Memento.##6#7{Memento.DefaultRecord}}, ::Int64, ::Int64) at array.jl:508),Pair{Symbol,Any}(:stacktrace, StackFrame[collect_to!(::Array{Pair{Symbol,_} where _,1}, ::Base.Generator{Array{Symbol,1},Memento.##6#7{Memento.DefaultRecord}}, ::Int64, ::Int64) at array.jl:508, collect_to!(::Array{Pair{Symbol,DateTime},1}, ::Base.Generator{Array{Symbol,1},Memento.##6#7{Memento.DefaultRecord}}, ::Int64, ::Int64) at array.jl:518, _collect(::Array{Symbol,1}, ::Base.Generator{Array{Symbol,1},Memento.##6#7{Memento.DefaultRecord}}, ::Base.EltypeUnknown, ::Base.HasShape) at array.jl:489, Type at records.jl:66 [inlined]]),Pair{Symbol,Any}(:date, 2018-08-06T20:47:03),Pair{Symbol,Any}(:pid, 1))
 stack:[collect_to!@array.jl:508, collect_to!@array.jl:518, _collect@array.jl:489, Type@records.jl:66]

I'll look into this more tomorrow.

Upon further inspection, it looks like stacktrace doesn't work properly with the task based approach we're using to write to multiple handlers concurrently. For now, I'm going to disable async writing to handlers. I believe a better approach going forward will be for handlers to opt into asynchronously emit records. We'll still need to be careful in the emit methods that @async is being called after we've formatted the record.