idiap_devtools.logging#

logging.Logger setup and stream separation

Functions

setup(logger_name[, format, ...])

This function returns a logger object that is ready for console logging.

idiap_devtools.logging.setup(logger_name, format='[%(levelname)s][%(name)s][%(asctime)s] %(message)s', low_level_stream=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>, high_level_stream=<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>)[source]#

This function returns a logger object that is ready for console logging.

Retrieves (as with logging.getLogger()) the given logger, and then attaches 2 handlers (defined on the module) to it:

  1. A logging.StreamHandler to output messages with level equal or lower than logging.INFO to the text-I/O stream low_level_stream. This is implemented by attaching a filter to the respective stream-handler to limit message records at this level.

  2. A logging.StreamHandler to output warning, error messages and above to the text-I/O stream high_level_stream, with an internal level set to logging.WARNING.

A new formatter, with the format string as defined by the format argument is set on both handlers. In this way, the global logger level can still be controlled from one single place. If output is generated, then it is sent to the right stream.

Parameters:
  • logger_name (str) – The name of the module to generate logs for

  • format (str) – The format of the logs, see logging.LogRecord for more details. By default, the log contains the logger name, the log time, the log level and the massage.

  • low_level_stream (TextIO) – The stream where to output info messages and below

  • high_level_stream (TextIO) – The stream where to output warning messages and above

Return type:

Logger

Returns:

The configured logger. The same logger can be retrieved using the logging.getLogger() function.