-
-
Notifications
You must be signed in to change notification settings - Fork 211
Description
openml registers a streamhandler with the root logger, because it uses logging.basicConfig. That functions registers a logging.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:
import logging
if __name__ == '__main__':
# Commenting out the line below prevents `basicConfig` from registering a streamhandler
# logging.getLogger().addHandler(logging.NullHandler())
log = logging.getLogger('mypackage')
log.setLevel(logging.DEBUG)
log.info("Message one") # first call, no log handler registered
import openml
log.info("Message two") # second call, log handler registered by openmloutput:
[INFO] [14:47:46:mypackage] Message two
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 a logging.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 adding logging.NullHandler. I think we should avoid using logging.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') or log = logging.getLogger(__name__)). We should make sure to take into account the verbosity level as defined in the config when doing so.