Initializing root logger
adamgayoso opened this issue · comments
I feel that the root logger should not be set by a single python package. This is creating double logging for our package that depends on Flax, Jax, etc, as we have our own handler on the logger in our namespace.
abseil-py/absl/logging/__init__.py
Lines 559 to 560 in 3e4749a
I could be wrong but in this code:
abseil-py/absl/logging/__init__.py
Lines 1246 to 1252 in 3e4749a
The handler should be added with _absl_logger.addHandler(_absl_handler)
while logging.setLoggerClass(ABSLLogger)
should be _absl_logger.setLoggerClass(ABSLLogger)
with the surrounding lines removed
(1) Re the first reference of calling logging.basicConfig()
: this is the same behavior in Python's own std logging library:
(2) Re the second reference, the _absl_handler
is created at absl.logging
import time but not added to any logger, to avoid exactly the double logging issue. The handler is only added to the root logger when use_absl_handler()
is explicitly called, e.g. if you use absl.app.run()
(see
Line 372 in 3e4749a
So if you are seeing double logging:
- because of the
logging.basicConfig()
call from (1), then it's the same behavior if use you std logging statements. - because of half of the logs are from the _absl_handler, then somewhere
use_absl_handler()
is called (or much less likely that you explicitly added _absl_handler to a logger).
Thank you, our problem was actually found elsewhere! Thanks for the info!