MLJ.jl
MLJ.jl copied to clipboard
[FR] allow disabling of logging
Using MLJ generates a bunch of statements like
[ Info: Model metadata loaded from registry. d/fit-and-predict.md, ex2)
I've executing everything after a Logging.disable_logging(Logging.LogLevel(3_000))
but this did not have the intended effect (though possibly it had the intended effect for MLJ just not for MLJModels or something along those lines)
Would it be possible to expose a function which switches all of this off? like a set_verbosity(0)
?
As an alternative, an environment variable to set verbosity would be nice, since then we can disable logging that happens before the package is fully loaded.
So, is the suggestion something like this:
In MLJBase.jl:
BASE_VERBOSITY[] = Ref(1)
abs_verbosity(verbosity) = BASE_VERBOSITY + verbosity - 1
_integer(v::Integer) = v
_integer(s::String) = parse(Int, s)
set_verbosity(verbosity) = (BASE_VERBOSITY[] = _integer(verbosity))
...
function __init__()
...
set_verbosity(ENV["MLJ_VERBOSITY"])
...
end
And we replace every test in MLJBase/MLJModels/MLJ of the form "if verbosity ..." with "if abs_verbosity(verbosity) ...", and so forth?
Sounds good though the replace every test does not seem necessary?
I was thinking we have color_off()
maybe we can have logging_off()
.
Since all our logging is generated with @info
or @warn
we can avoid all that refactoring involved in my earlier suggestion, using julia functionality: See https://docs.julialang.org/en/v1/stdlib/Logging/#
Also, rather than adjusting a BASE_LEVEL, I agree it is conceptually simpler to just turn all logging on or off.
The simplest thing is to manipulate julia's logging globally. I think this would be fine, and the entire implementation, including looking at env variable, is:
import Logging
silent() = Loging.disable_logging(Logging.Warn)
loud() = Logging.disable_loggin(Loggin.Debug)
...
function __init__()
...
if haskey(ENV, "MLJ_SILENT") && parse(Bool, ENV["MLJ_SILENT"])
silent()
else
loud()
end
...
end
...
That's it.
Wouldn't that prevent users from using Logging themselves?
This would indeed switch all logging off, not just the MLJ logging.
Does anyone know how to control the logging of just one package?
probably best to ask that on Discourse?
https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732/2?
In view of the post above, it seems to me that controlling logging is more the user's responsibility than the package's. Any activity he wants different logging levels for, he can just wrap appropriately.
@tlienart Do you think we could close this?
I’m a bit confused though, my initial question was to enable log surpression for the whole of MLJ in one function call; IMO this could be achieved by only logging if a toggle is on and then indeed when the logging is on, the user could additionally reduce it or whatever
But it would be good to have the possibility to not log anything