cdsapi
cdsapi copied to clipboard
cdsapi.Client changes logging level of external loggers
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.
I just came here to report this :) @kanderso-nrel's patch in #47 looks like a good fix. https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library has some additional guidance on logging for libraries.