idiap_devtools.logging¶
logging.Logger
setup and stream separation.
Functions
|
Return 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]¶
Return 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:A
logging.StreamHandler
to output messages with level equal or lower thanlogging.INFO
to the text-I/O streamlow_level_stream
. This is implemented by attaching a filter to the respective stream-handler to limit message records at this level.A
logging.StreamHandler
to output warning, error messages and above to the text-I/O streamhigh_level_stream
, with an internal level set tologging.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 forformat – 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 belowhigh_level_stream (
TextIO
) – The stream where to output warning messages and above
- Return type:
- Returns:
The configured logger. The same logger can be retrieved using the
logging.getLogger()
function.