GOLEM icon indicating copy to clipboard operation
GOLEM copied to clipboard

[Bug] For some reason your module creates a handler(-s) for root logger

Open Roman223 opened this issue 10 months ago • 0 comments

Recently during work on another project I found that w/o implicit init of my logger it usually has strange handler in parent logger (root logger).

logger = get_logger("estimators", level=logging.DEBUG) # w/o clearing attributes with init
logger2 = Logger("estimators", level=logging.DEBUG) # w/ clearing

print(logger.handlers)
print(logger.parent)
print(logger.parent.handlers)
print("__")
print(logger2.handlers)
print(logger2.parent)

logger.info("test message")
print("separator")
logger2.info("test message")

Out:

[<RichHandler (NOTSET)>]
<RootLogger root (INFO)>
[<StreamHandler <stdout> (INFO)>, <RotatingFileHandler /tmp/GOLEM/log.log (INFO)>]
__
[<RichHandler (DEBUG)>]
None
[03/11/25 13:07:31] INFO     test message                   base_estimator.py:24
2025-03-11 13:07:31,646 - test message
separator
[03/11/25 13:07:31] INFO     test message                   base_estimator.py:26

This bug eventually leads to log duplication.

PS: For first time, there were 3 handlers, one from BAMT, but we do fix it by disabling formatter for root logger.

Roman223 avatar Mar 11 '25 10:03 Roman223