MLJ.jl icon indicating copy to clipboard operation
MLJ.jl copied to clipboard

[FR] allow disabling of logging

Open tlienart opened this issue 5 years ago • 11 comments

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)?

tlienart avatar Oct 07 '19 15:10 tlienart

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.

jpsamaroo avatar Oct 14 '19 22:10 jpsamaroo

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?

ablaom avatar Oct 15 '19 02:10 ablaom

Sounds good though the replace every test does not seem necessary?

I was thinking we have color_off() maybe we can have logging_off().

tlienart avatar Oct 15 '19 07:10 tlienart

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.

ablaom avatar Apr 30 '20 01:04 ablaom

Wouldn't that prevent users from using Logging themselves?

tlienart avatar Apr 30 '20 08:04 tlienart

This would indeed switch all logging off, not just the MLJ logging.

ablaom avatar Apr 30 '20 20:04 ablaom

Does anyone know how to control the logging of just one package?

ablaom avatar May 19 '20 01:05 ablaom

probably best to ask that on Discourse?

tlienart avatar May 19 '20 07:05 tlienart

https://discourse.julialang.org/t/controlling-the-new-logger-debug-messages/13732/2?

ablaom avatar May 25 '20 22:05 ablaom

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?

ablaom avatar Jun 25 '20 03:06 ablaom

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

tlienart avatar Jun 25 '20 07:06 tlienart