Closed rofinn closed 6 years ago
An alternative suggestion: loggers should start off with their logging level being set to "default". The "default" level is directly tied to the root or parent logger. This means if you set the root logger to "debug" then all loggers at the "default" level are also at the "debug" level.
Such a change would make Memento.config("debug")
allow users to see debug messages for all loggers (provided the logger levels are set to "default").
Looks like this is mostly solved with julia's broadcast syntax.
julia> using Memento
julia> Memento.config("info")
Logger(root)
julia> getlogger.(("Foo", "Bar", "Baz"))
(Logger(Foo), Logger(Bar), Logger(Baz))
julia> map(getlevel, values(Memento._loggers))
4-element Array{String,1}:
"info"
"warn"
"warn"
"warn"
julia> setlevel!.(getlogger.(("Foo", "Baz")), "info")
("info", "info")
julia> map(getlevel, values(Memento._loggers))
4-element Array{String,1}:
"info"
"info"
"warn"
"info"
We'll probably just want to support a recursive flag on config
and setlevel!
.
Currently,
Memento.config("info")
only sets the logging level for the root logger and you need to set the level for each sublogger (e.g.,setlevel!(getlogger("Foo"), "info")
,setlevel!(getlogger("Foo.Bar"), "info")
) because the default is"warn"
. It would be nice to have a nice interface that allows batch setting of logging levels.Proposed Solution:
recursive
flag tosetlevel!
which will set the logging level for all parents of the logger. For example,setlevel!(getlogger("Foo.Bar.Baz"), "info")
would set the loggers"root"
,"Foo"
and"Foo.Bar"
to"info"
.setlevel!
(ie:setlevel!(["", "Foo", "Foo.Bar", "Foo.Bar.Baz"], "info")
)Another solution would be to allow
Memento.config
to take a list of logger names. This could cause some confusion as to whether each logger will be configured with a default handler. Similarly,Memento.config
already does a lot, so I'm less inclined to add features to it.