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.
JsonEncoder
🔗
Bases: JSONEncoder
A custom encoder extending json.JSONEncoder
JsonFormatter
🔗
JsonFormatter(
*args,
json_default: OptionalCallableOrStr = None,
json_encoder: OptionalCallableOrStr = None,
json_serializer: Union[Callable, str] = json.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
TYPE:
|
json_encoder |
custom JSON encoder
TYPE:
|
json_serializer |
a |
json_indent |
indent parameter for the |
json_ensure_ascii |
TYPE:
|
kwargs |
DEFAULT:
|
add_fields
🔗
Extract fields from a LogRecord for logging
This method can be overridden to implement custom logic for adding fields.
PARAMETER | DESCRIPTION |
---|---|
log_record |
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
|
format
🔗
Formats a log record and serializes to json
PARAMETER | DESCRIPTION |
---|---|
record |
the record to format
TYPE:
|
jsonify_log_record
🔗
Returns a json string of the log record.