utils.logutils module

class utils.logutils.IndentationAdapter(logger, extra=None, padding='t', offset=6)

Bases: logging.LoggerAdapter

Custom LoggerAdapter adding indentation to log messages depending on the nesting depth of the calling function.

Parameters:
  • logger (Logger) – The Logger instance to use as a base for the adapter.
  • extra (dict, optional) – Special argument for LoggerAdapter, is not used here. Default value is {}.
  • padding (str, optional) – The string to be used as padding. Default value is "        ".
  • offset (int, optional) – Indentation is reduced by offset levels. Default value is 6.
_indent()

Returns the indentation level using the current size of the stack and the specified offset. Minimum indentation is 0.

process(msg, kwargs)

Inserts indentation into message string.

class utils.logutils.ColoredFormatter(fmt, datefmt=None, style='%', use_color=True)

Bases: logging.Formatter

Custom Formatter adding color to log messages depending on the level of the message. DEBUG – dark white INFO – white WARNING – yellow ERROR – red CRITICAL – red

format(record)

Adds color escapes before passing the record to the default format method. Messages with level higher than INFO are printed bold.