ocrd_utils.logging module

Logging setup

By default: Log with lastResort logger, usually STDERR.

Logging can be overridden either programmatically in code using the library or by creating one or more of

  • /etc/ocrd_logging.py

  • $HOME/ocrd_logging.py

  • $PWD/ocrd_logging.py

These files will be executed in the context of ocrd/ocrd_logging.py, with logging global set.

Changes as of 2023-08-20:

  • Try to be less intrusive with OCR-D specific logging conventions to make it easier and less surprising to define logging behavior when using OCR-D/core as a library

  • Change setOverrideLogLevel to only override the log level of the ocrd logger and its descendants

  • initLogging will set exactly one handler, for the root logger or for the ocrd logger.

  • Child loggers should propagate to the ancestor logging (default behavior of the logging library - no more PropagationShyLogger)

  • disableLogging only removes any handlers from the ocrd logger

ocrd_utils.logging.disableLogging(silent=True)[source]

Disables all logging of the ocrd logger and descendants

Keyword Arguments:

silent (-) – Whether to log logging behavior by printing to stderr

ocrd_utils.logging.getLevelName(lvl)[source]

Get (string) python logging level for (string) spec-defined log level name.

ocrd_utils.logging.getLogger(*args, **kwargs)[source]

Wrapper around logging.getLogger that calls initLogging() if that wasn’t explicitly called before.

ocrd_utils.logging.initLogging(builtin_only=False, force_reinit=False, silent=True)[source]

Reset ocrd logger, read logging configuration if exists, otherwise use basicConfig

initLogging is to be called by OCR-D/core once, i.e.
  • for the ocrd CLI

  • for the processor wrapper methods

Other processes that use OCR-D/core as a library can, but do not have to, use this functionality.

Keyword Arguments:
  • builtin_only (-) – Whether to search for logging configuration on-disk (False) or only use the hard-coded config (True). For testing

  • force_reinit (-) – Whether to ignore the module-level _initialized_flag. For testing only.

  • silent (-) – Whether to log logging behavior by printing to stderr

ocrd_utils.logging.setOverrideLogLevel(lvl, silent=True)[source]

Override the output log level of the handlers attached to the ocrd logger.

Parameters:
  • lvl (string) – Log level name.

  • silent (boolean) – Whether to log the override call