Skip to content
This repository was archived by the owner on Dec 21, 2024. It is now read-only.

Commit f9c20e2

Browse files
author
Zakaria Zajac
authored
Merge pull request #42 from philtay/serializer
Allow alternative JSON encoders
2 parents b36cfa4 + fdbc8bd commit f9c20e2

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/pythonjsonlogger/jsonlogger.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ def __init__(self, *args, **kwargs):
5656
:param json_default: a function for encoding non-standard objects
5757
as outlined in http://docs.python.org/2/library/json.html
5858
:param json_encoder: optional custom encoder
59+
:param json_serializer: a :meth:`json.dumps`-compatible callable
60+
that will be used to serialize the log record.
5961
:param prefix: an optional string prefix added at the beginning of
6062
the formatted string
6163
"""
6264
self.json_default = kwargs.pop("json_default", None)
6365
self.json_encoder = kwargs.pop("json_encoder", None)
66+
self.json_serializer = kwargs.pop("json_serializer", json.dumps)
6467
self.prefix = kwargs.pop("prefix", "")
6568
#super(JsonFormatter, self).__init__(*args, **kwargs)
6669
logging.Formatter.__init__(self, *args, **kwargs)
@@ -104,9 +107,9 @@ def process_log_record(self, log_record):
104107

105108
def jsonify_log_record(self, log_record):
106109
"""Returns a json string of the log record."""
107-
return json.dumps(log_record,
108-
default=self.json_default,
109-
cls=self.json_encoder)
110+
return self.json_serializer(log_record,
111+
default=self.json_default,
112+
cls=self.json_encoder)
110113

111114
def format(self, record):
112115
"""Formats a log record and serializes to json"""

0 commit comments

Comments
 (0)