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'>, formatter=None)[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.
If you do not provide a
formatterargument, a new formatter, with the format string as defined by theformatargument 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.You can provide a custom formatter if
formatis not sufficient to customize the looks of your logs (e.g. you want to add colors).- 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 message. Ignored if ``formatter`` is set.low_level_stream (
TextIO) – The stream where to output info messages and belowhigh_level_stream (
TextIO) – The stream where to output warning messages and aboveformatter (
Formatter|None) – A formatter to replace the defaultlogging.Formatter.
- Return type:
- Returns:
The configured logger. The same logger can be retrieved using the
logging.getLogger()function.