jgdv.logging.format.colour
Type Aliases
Classes
Stream Formatter for logging, enables use of colour sent to console |
|
Force Colour Command codes to be stripped out of a string. |
Module Contents
- jgdv.logging.format.colour.StyleChar: TypeAlias = Literal['%', '{', '$']
- class jgdv.logging.format.colour.ColourFormatter(*, fmt=None, style=None)[source]
Bases:
logging.FormatterStream Formatter for logging, enables use of colour sent to console
Guarded Formatter for adding colour. Uses the sty module. If sty is missing, behaves as the default formatter class
# Do not use for on filehandler Usage reminder: # Create stdout handler for logging to the console (logs all five levels) stdout_handler = logging.StreamHandler() stdout_handler.setFormatter(ColourFormatter(fmt)) logger.addHandler(stdout_handler)
- Parameters:
fmt (jgdv.Maybe[str])
style (jgdv.Maybe[StyleChar])
- apply_colour_mapping(mapping) <Unknown>[source]
applies a mapping of colours by treating each value as a pair of attrs of sty
eg: {logging.DEBUG: (“fg”, “blue”), logging.INFO: (“bg”, “red”)}
- Parameters:
mapping (dict)
- Return type:
None
- format(record) <Unknown>[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.
- Parameters:
record (logging.LogRecord)
- Return type:
- _default_style: StyleChar = '{'
- class jgdv.logging.format.colour.StripColourFormatter(*, fmt=None, style=None)[source]
Bases:
logging.FormatterForce Colour Command codes to be stripped out of a string. Useful for when you redirect printed strings with colour to a file
- Parameters:
fmt (jgdv.Maybe[str])
style (jgdv.Maybe[StyleChar])
- format(record) <Unknown>[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.
- Parameters:
record (logging.LogRecord)
- Return type:
- _colour_strip_re: jgdv.Rx
- _default_style: StyleChar = '{'