Skip to content

quantpylib.logger.formatters

JSONFormatter

Bases: Formatter

A custom JSON formatter for logging.

This formatter converts log records to JSON format. It includes level, time, and message by default and can optionally include additional attributes. Key-value pairs in the extra variable of logs are included in the JSON log.

Parameters:

Name Type Description Default
include_attrs list

List of additional attributes to include in the log record. Valid entries in the list can be found in quantpylib.logger.utils.

[]

__init__(include_attrs=[])

Initializes the JSONFormatter.

Parameters:

Name Type Description Default
include_attrs list

List of additional attributes to include in the log record. Defaults to an empty list. Valid entries in the list can be found in quantpylib.logger.utils.

[]

format(record)

Formats a log record and converts it to a JSON string.

Parameters:

Name Type Description Default
record LogRecord

The log record to format.

required

Returns:

Name Type Description
str

The JSON-formatted log record as a string.