ColoredFormatter#

Custom formatter to add color to log messages based on their severity level.

This class extends logging.Formatter to provide colored output for log messages, allowing for visual differentiation of log levels in the console.

modules.colored_formatter.COLORS

Dictionary mapping log levels to color codes.

Type:

dict

format(record

logging.LogRecord) -> str: Format the log record with color based on its severity level.

Parameters:

record (logging.LogRecord) – The log record to format.

Returns:

The formatted log message with color.

Return type:

str

class modules.colored_formatter.ColoredFormatter[source]

Bases: Formatter

Custom formatter to add color to log messages based on their severity level.

COLORS

Dictionary mapping log levels to color codes.

Type:

dict

COLORS = {'CRITICAL': '\x1b[41m', 'DEBUG': '\x1b[34m', 'ERROR': '\x1b[31m', 'INFO': '\x1b[32m', 'RESET': '\x1b[0m', 'WARNING': '\x1b[33m'}
format(record)[source]

Format the log record with color based on its severity level.

Parameters:

record (logging.LogRecord) – The log record to format.

Returns:

The formatted log message with color.

Return type:

str