Skip to content

openml registers handler on root logger #736

@PGijsbers

Description

@PGijsbers

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 openml

output:

[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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions