color_bucket_logger.term_mapper module

class color_bucket_logger.term_mapper.TermColorMapper(fmt=None, default_color_by_attr=None, color_groups=None, format_attrs=None, auto_color=False)[source]

Bases: color_bucket_logger.mapper.BaseColorMapper

get_colors_for_record(record_context, format_attrs)[source]

For a record_context dict, compute color for each field and return a color dict

get_level_color(levelname, levelno)[source]

return color idx for logging levelname and levelno

get_name_color(name, perturb=None)[source]

return color idx for ‘name’ string

get_process_colors(record_context)[source]

Given process/thread info, return reasonable colors for them.

Roughly:

  • attempts to get a unique color per ‘processName’
  • attempts to get a unique color per ‘process’ (pid)
    • attempt to make those the same for “MainProcess”
    • for any other ‘processName’, the pname color and the pid color can be different
  • if ‘threadName’ is “MainThread”, make tname_color and tid_color match “MainProcess” pname_color and pid_color
  • other ‘threadName’ values get a new color and new tid_color

Notes

This doesn’t track any state so there is no ordering or prefence to the colors given out.

Parameters:record_context (dict) – The log record_context to calculate process colors for
Returns:The color indexes for ‘processName’, ‘process’, ‘threadName’, and ‘thread’
Return type:int, int, int, int
get_thread_color(threadid)[source]

Calculate the color index for a threadid (tid) number

Parameters:threadid (int) – The value of the LogRecord.threadid attribute (the tid)
Returns:
  • int
  • The color index to use
LEVEL_COLORS = {'CRITICAL': 1, 'DEBUG': 4, 'ERROR': 1, 'INFO': 2, 'SUBDEBUG': 4, 'SUBWARNING': 3, 'TRACE': 4, 'WARNING': 3}

A fixed map of logging level to color used by the default get_level_color()

NUMBER_OF_COLORS = 203