core icon indicating copy to clipboard operation
core copied to clipboard

ocrd_utils.initLogging: also add handler to root logger

Open bertsky opened this issue 1 year ago • 7 comments

As a follow-up to https://github.com/OCR-D/core/commit/ccb416b13e7f91781568fda8e60ad8182bfea88c, but more general:

initLogging should always affect the root logger '', too. (Not just when disabling logging.)

Reasons:

  • to be consistent with file config (which by default also configures the unqualified root logger for our default handlers
  • to prevent imported libraries from initializing logging on their own (like import tensorflow) – the place to check whether logging has been set up yet is always getLogger('').hasHandlers(), also in Python's logging.basicConfig BTW

I know we deliberately changed this to exclude the root logger earlier. But I cannot find the reasoning behind that anymore. Maybe "we are a library, not an application"? Well, I agree actually, but then just don't call initLogging. (Perhaps at that time we got distracted by the fact that we still did call initLogging unconditionally when importing ocrd_utils.logging.)

BTW, IMO most places (core and modules code) can get their loggers from Python stdlib's logging.getLogger instead of our ocrd_utils.logging.getLogger, because we don't add anything to that nowadays.

bertsky avatar Oct 09 '24 16:10 bertsky