-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
openml registers handler on root logger #736
Comments
Thanks for bringing that up. Actually, the package should have a good default logging behavior, but should allow flexible configuration and fully disabling it, too. I currently don't know the best way to achieve this unfortunately. |
What do you consider 'good default logging behavior'? For me it would be:
|
I would not show debug messages by default, but I agree on the logger name.
Agreed.
I didn't think of logging to the openml directory by default, but that appears to be a great idea. The user could still configure the package to output to the command line. |
I'm not advocating showing (to console?) debug messages by default either. There's two levels to set, that of the >>> import logging
>>> openml_log = logging.getLogger('openml')
>>> openml_log.setLevel(logging.DEBUG)
>>> openml_log.error("With the exception of error-level messages")
With the exception of error-level messages
>>> openml_log.info("No messages are written to console.")
>>> # if you want to change this default behavior, and have not even error messages
... # written to stdout, you can add a `logging.NullHandler()`.
... # Now we add a 'logging.StreamHandler' to actually write to stdout
...
>>> import sys
>>> sh = logging.StreamHandler(sys.stdout)
>>> sh.setLevel(logging.INFO)
>>> openml_log.addHandler(sh)
>>> openml_log.info("Now info messages are also written to stdout.")
Now info messages are also written to stdout.
>>> openml_log.debug("but not debug messages.") # because `sh.level == logging.INFO`
>>> sh.setLevel(logging.DEBUG)
>>> openml_log.debug("Now even DEBUG messages are written to stdout.")
Now even DEBUG messages are written to stdout.
>>> openml_log.setLevel(logging.ERROR)
>>> openml_log.warning("By setting the log level of the log differently, handlers wont receive all messages.") # because `openml_log.level == logging.ERROR`
>>> # Nothing written to stdout By setting the log level of the log (not the handler!) to I think the proposed changes will be relatively easy to implement. I don't have the time currently (when I do, I'll first finish the 'short names' PR). It's a low priority issue but if it stays open I can tackle it end of the month/in August. |
Got it, that totally makes sense. |
openml
registers a streamhandler with the root logger, because it useslogging.basicConfig
. That functions registers alogging.StreamHandler
with the root logger if it does not yet have a handler. This means that logging of other packages may automatically be processed by this streamhandler. An example to demonstrate:output:
Due to the
logging.basicConfig
behavior, if a handler already is registered (such as is done in the commented out line), it will not add alogging.StreamHandler
. So there is no output if the relevant line of code is commented out.I also see a verbosity in the config defaults, but I don't see it used anywhere. Am I missing something?
I think adding a
logging.StreamHandler
to the root logger is undesirable behavior. Developers should have full autonomy over their logging handlers without resorting to addinglogging.NullHandler
. I think we should avoid usinglogging.basicConfig
to set our streamhandler. Instead, we should register a streamhandler to an openml specific logger instead of the root (i.e.log = logging.getLogger('openml')
orlog = logging.getLogger(__name__)
). We should make sure to take into account the verbosity level as defined in the config when doing so.The text was updated successfully, but these errors were encountered: