Skip to content

cdsapi.Client changes logging level of external loggers #46

@kandersolar

Description

@kandersolar

The cdsapi.Client constructor includes a call to logging.basicConfig which modifies the logging behavior for loggers unrelated to cdsapi. Here's an example:

import logging
import cdsapi

# external logger initially at WARNING level:
my_logger = logging.getLogger('my_logger')
print(my_logger)  # <Logger my_logger (WARNING)>
my_logger.info('this is not printed')
client = cdsapi.Client()
# external logger now set to INFO:
print(my_logger)  # <Logger my_logger (INFO)>
my_logger.info('this is printed')

output:

<Logger my_logger (WARNING)>
<Logger my_logger (INFO)>
2021-08-20 07:52:24,840 INFO this is printed

And in fact it modifies the log level of loggers from a bunch of other packages; check out the contents of logging.root.manager.loggerDict before and after creating a Client object and you'll see many of them switch from WARNING to INFO as well.

I have a patch ready to fix this and will submit a PR shortly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions