Skip to content

Commit 039f1cd

Browse files
committed
Small refactoring which allow to customize the way the record dict is converted to json
1 parent 5343858 commit 039f1cd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

json_log_formatter/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,14 @@ def format(self, record):
6767
# argument passed in.
6868
if mutated_record is None:
6969
mutated_record = json_record
70-
return self.json_lib.dumps(mutated_record)
70+
return self.to_json(mutated_record)
71+
72+
def to_json(self, record):
73+
"""Convert record dict to a json string
74+
75+
Override this method to change the way dict is converted to JSON.
76+
"""
77+
return self.json_lib.dumps(record)
7178

7279
def extra_from_record(self, record):
7380
"""Returns `extra` dict you passed to logger.

0 commit comments

Comments
 (0)