Colors

Log prefixes colored by event, with ANSI codes.

CACHE_RESULTS = {"LOG_PREFIX": "cache_results.colors.log_prefix"}

Hits are green, misses red, invalidations gray, and other messages, such as errors, bold red. Colors can be changed with CACHE_RESULTS["LOG_COLORS"], a dict from event ("hit", "miss", "invalidate" or "") to an ANSI code.

cache_results.colors.DEFAULT_COLORS = {'': '\x1b[1;31m', 'hit': '\x1b[32m', 'invalidate': '\x1b[37m', 'miss': '\x1b[31m'}

The color of each event, unless CACHE_RESULTS["LOG_COLORS"] sets it.

cache_results.colors.RESET = '\x1b[0m'

The ANSI code that ends a color.

cache_results.colors.log_prefix(text: str, event: str = '') → str[source]

Color the start of a log message by its event.

Parameters:
  • text (str) – e.g. cache_results.decorators.@cache_results().

  • event (str) – "hit", "miss", "invalidate" or "".

Returns:

The colored text, or text for an event without a color.

Return type:

str