pythonjsonlogger.json
🔗
JSON formatter using the standard library's json
for encoding.
Module contains the JsonFormatter
and a custom JsonEncoder
which supports a greater
variety of types.
CLASS | DESCRIPTION |
---|---|
JsonEncoder |
A custom encoder extending json.JSONEncoder |
JsonFormatter |
JSON formatter using the standard library's |
JsonEncoder
🔗
Bases: JSONEncoder
A custom encoder extending json.JSONEncoder
METHOD | DESCRIPTION |
---|---|
format_datetime_obj |
Format datetime objects found in |
JsonFormatter
🔗
JsonFormatter(
*args,
json_default: Optional[Callable] = None,
json_encoder: Optional[Callable] = None,
json_serializer: Callable = dumps,
json_indent: Optional[Union[int, str]] = None,
json_ensure_ascii: bool = True,
**kwargs
)
Bases: BaseJsonFormatter
JSON formatter using the standard library's json
for encoding
PARAMETER | DESCRIPTION |
---|---|
args
|
DEFAULT:
|
json_default
|
a function for encoding non-standard objects |
json_encoder
|
custom JSON encoder |
json_serializer
|
a |
json_indent
|
indent parameter for the |
json_ensure_ascii
|
TYPE:
|
kwargs
|
DEFAULT:
|
METHOD | DESCRIPTION |
---|---|
add_fields |
Extract fields from a LogRecord for logging |
format |
Formats a log record and serializes to json |
formatException |
Format and return the specified exception information. |
formatStack |
Format and return the specified stack information. |
jsonify_log_record |
Returns a json string of the log data. |
parse |
Parses format string looking for substitutions |
process_log_record |
Custom processing of the data to be logged. |
serialize_log_record |
Returns the final representation of the data to be logged |
add_fields
🔗
Extract fields from a LogRecord for logging
This method can be overridden to implement custom logic for adding fields.
PARAMETER | DESCRIPTION |
---|---|
log_data
|
data that will be logged |
record
|
the record to extract data from
TYPE:
|
message_dict
|
dictionary that was logged instead of a message. e.g
|
Changed in 4.0: log_record
renamed to log_data
format
🔗
Formats a log record and serializes to json
PARAMETER | DESCRIPTION |
---|---|
record
|
the record to format
TYPE:
|
formatException
🔗
Format and return the specified exception information.
If exc_info_as_array is set to True, This method returns an array of strings.
formatStack
🔗
Format and return the specified stack information.
If stack_info_as_array is set to True, This method returns an array of strings.
jsonify_log_record
🔗
Returns a json string of the log data.