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 theocrdlogger and its descendants
initLogging()will set exactly one handler, for the root logger or for theocrdlogger.Child loggers should propagate to the ancestor logging (default behavior of the logging library - no more
PropagationShyLogger)
disableLogging()only removes any handlers from theocrdlogger
- ocrd_utils.logging.disableLogging(silent=True)[source]¶
Disables all logging of the
ocrdlogger 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.getLoggerthat callsinitLogging()if that wasn’t explicitly called before.
- ocrd_utils.logging.initLogging(builtin_only=False, force_reinit=False, silent=True)[source]¶
Reset
ocrdlogger, read logging configuration if exists, otherwise uselogging.basicConfig()- This is to be called by OCR-D/core only once, i.e.
for the
ocrdCLIfor 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 testingforce_reinit (-) – Whether to ignore the module-level
_initialized_flag. For testing onlysilent (-) – Whether to log logging behavior by printing to stderr