Skip to content

Commit

Permalink
disableLogging: re-instate root logger, to
Browse files Browse the repository at this point in the history
  • Loading branch information
bertsky committed Aug 28, 2024
1 parent a59ba6a commit 554a67d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ocrd_utils/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,13 @@ def disableLogging(silent=not config.OCRD_LOGGING_DEBUG):
# logging.basicConfig(level=logging.CRITICAL)
# logging.disable(logging.ERROR)
# remove all handlers for the ocrd logger
for logger_name in ROOT_OCRD_LOGGERS:
for logger_name in ROOT_OCRD_LOGGERS + ['']:
for handler in logging.getLogger(logger_name).handlers[:]:
logging.getLogger(logger_name).removeHandler(handler)
for logger_name in LOGGING_DEFAULTS:
logging.getLogger(logger_name).setLevel(logging.NOTSET)
# Python default log level is WARNING
logging.root.setLevel(logging.WARNING)

# Initializing stream handlers at module level
# would cause message output in all runtime contexts,
Expand Down
1 change: 1 addition & 0 deletions tests/test_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def test_loglevel_override(self):
pytest.skip(f"ocrd_logging.conf found at {get_logging_config_files()}, skipping logging test")
import logging
disableLogging()
assert logging.getLogger('').getEffectiveLevel() == logging.WARNING
assert logging.getLogger('ocrd').getEffectiveLevel() == logging.WARNING
initLogging()
assert logging.getLogger('ocrd').getEffectiveLevel() == logging.INFO
Expand Down

0 comments on commit 554a67d

Please sign in to comment.