python-coloredlogs icon indicating copy to clipboard operation
python-coloredlogs copied to clipboard

Consider not setting level on the colored handler

Open gst opened this issue 7 years ago • 1 comments

Hi,

happy new user of coloredlogs for its out of the box nice feature.

please consider this use case:

In [1]: import coloredlogs

In [2]: import logging

In [3]: logger = logging.getLogger()

In [4]: coloredlogs.install()

In [5]: logger.setLevel(logging.DEBUG)

In [6]: logger.debug('foo')

In [7]: 

I find it a bit counter intuitive. Naively I'd have expected to see my "foo" debug call.

All would be good if coloredlogs wouldn't set the level on the actual handler but only on the root logger (or the explicitly passed one otherwise)..

wdyt ?

thx.

gst avatar Apr 06 '18 17:04 gst

I agree, I meet the same problem. I expect to see colored logs in all loggers, and allow loggers which level lower than root logger to emit messages.

My workaround:

coloredlogs.install(**colored_params)  # add colored handler to root logger
logging.getLogger().setLevel(logging.WARNING)  # reset root logger level
for h in logging.getLogger().handlers:
    h.setLevel(logging.NOTSET)  # reset colored handler level

guyskk avatar Jul 05 '18 07:07 guyskk