Skip to content

RecursiveJSON format? #7

Description

@ericphanson

If the user logs something JSON-able, it might be nice to recurse into that. E.g.

julia> global_logger(FormatLogger(LoggingFormats.JSON(), stderr))
FormatLogger(LoggingFormats.JSON(), Base.TTY(RawFD(15) open, 0 bytes waiting), true)

julia> @info "Hi" my_json = Dict("hi1" => Dict("hi2" => "bye"))
{"level":"info","msg":"Hi","module":"Main","file":"REPL[86]","line":1,"group":"REPL[86]","id":"Main_b58745e1","kwargs":{"my_json":"Dict(\"hi1\" => Dict(\"hi2\" => \"bye\"))"}}

could emit

julia> @info "Hi" my_json = Dict("hi1" => Dict("hi2" => "bye"))
{"level":"info","msg":"Hi","module":"Main","file":"REPL[90]","line":1,"group":"REPL[90]","id":"Main_b58745e3","kwargs":"my_json":{"hi1":{"hi2":"bye"}}}

It's less safe though, since

julia> struct A end

julia> @info "Hi" my_json = Dict("hi1" => Dict("hi2" => A()))
ERROR: ArgumentError: A doesn't have a defined `StructTypes.StructType`

which is probably why you didn't do this, but maybe it could be useful as a separate RecursiveJSON format?

(might also be a bit less painful with something like JuliaData/StructTypes.jl#61)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions