Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FR] allow disabling of logging #255

Open
tlienart opened this issue Oct 7, 2019 · 11 comments
Open

[FR] allow disabling of logging #255

tlienart opened this issue Oct 7, 2019 · 11 comments

Comments

@tlienart
Copy link
Collaborator

tlienart commented Oct 7, 2019

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

@jpsamaroo
Copy link
Collaborator

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.

@ablaom
Copy link
Member

ablaom commented Oct 15, 2019

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?

@tlienart
Copy link
Collaborator Author

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

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

@ablaom
Copy link
Member

ablaom commented Apr 30, 2020

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 ablaom added the triage label Apr 30, 2020
@tlienart
Copy link
Collaborator Author

Wouldn't that prevent users from using Logging themselves?

@ablaom
Copy link
Member

ablaom commented Apr 30, 2020

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

@ablaom
Copy link
Member

ablaom commented May 19, 2020

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

@tlienart
Copy link
Collaborator Author

probably best to ask that on Discourse?

@ablaom
Copy link
Member

ablaom commented May 25, 2020

@ablaom
Copy link
Member

ablaom commented Jun 25, 2020

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?

@tlienart
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants