libera_utils.logutil.JsonLogFormatter#
- class libera_utils.logutil.JsonLogFormatter(*args, add_log_record_attrs: tuple[str, ...] | None = None, add_asctime: bool = True, **kwargs)#
Bases:
FormatterAltered version of the CloudWatchLogFormatter provided in the watchtower library
Methods
converterformat(record)Format log message to a JSON string
formatException(ei)Format and return the specified exception information as a string.
formatStack(stack_info)This method is provided as an extension point for specialized formatting of stack information.
formatTime(record[, datefmt])Return the creation time of the specified LogRecord as formatted text.
usesTime()Check if the format uses the creation time of the record.
formatMessage
- __init__(*args, add_log_record_attrs: tuple[str, ...] | None = None, add_asctime: bool = True, **kwargs)#
- Parameters:
add_log_record_attrs (Optional, tuple) – Tuple of log record attributes to add to the resulting structured JSON structure that comes out of the logging formatter. To omit all, pass a empty tuple. Default None, which adds a default set of useful attributes.
add_asctime (bool) – If True, adds an ASCII (ISO 8601-like) timestamp to the log record. Default True.
Methods
format(record)Format log message to a JSON string
Attributes
default_msec_formatdefault_time_format- format(record: LogRecord) str#
Format log message to a JSON string
- Parameters:
record (logging.LogRecord) – Log record object containing the logged message, which may be a dict or a string
- Returns:
JSON formatted log message string
- Return type: