color_bucket_logger package

Top-level package for color_bucket_logger.

class color_bucket_logger.ColorFormatter(fmt=None, default_color_by_attr=None, color_groups=None, auto_color=False, datefmt=None, style=None)[source]

Bases: logging.Formatter

Base color bucket formatter

format(record)[source]

Format the specified record as text.

The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.

class color_bucket_logger.TermFormatter(fmt=None, default_color_by_attr=None, color_groups=None, auto_color=False, datefmt=None, color_mapper=None)[source]

Bases: color_bucket_logger.formatter.ColorFormatter

Formatter for terminals that colorizes attributes based on their value

Parameters:
  • fmt (str) – A logging.Formatter style log format string
  • default_color_by_attr (str, optional) – The name of the log record attribute whose color will used by default for other records if they do not have a color set (by either ‘auto_color’ or by ‘color_groups’)
  • color_groups (iterable, optional) –

    Define when a attribute should use the same color as another attribute.

    For example, to make the ‘processName’ and ‘message’ attributes use the same color as ‘process’.

    color_groups is a list of tuples. The first element of each tuple is the “leader” attribute, and the second element is a list of “follower” attributes.

    For the ‘process’ and ‘processName’ example:

    color_groups=[('process', ['processName', 'message']]
    
  • auto_color (boolean, optional) – If true, automatically calculate and use colors for each attribute. Defaults to False
  • datefmt (str, optional) – Date format string as used by logging.Formatter
color_bucket_logger.get_default_record_attrs(record_context, attr_list)[source]

Add default values to a log record_context for each attr in attr_list

Return a dict of {record_attr_name: some_default_value}. For example, a record_context with no ‘stack_info’ item would cause the return to be {‘stack_info’: None}.

For now, the default value is always None.