clapper.logging¶
logging.Logger setup and stream separation.
Functions
|
Return a logger object that is ready for console logging. |
- clapper.logging.setup(logger_name, format='[%(levelname)s] %(message)s (%(name)s, %(asctime)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.StreamHandlerto output messages with level equal or lower thanlogging.INFOto 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.StreamHandlerto 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
formatargument 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 (
str) – The format of the logs, seelogging.LogRecordfor 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.