Skip to content

Commit 47c1fb2

Browse files
authored
Merge pull request #14 from wulftone/patch-1
Add builtins example to README
2 parents f078b11 + 0a43fe0 commit 47c1fb2

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

README.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,21 @@ To do so you should override ``JSONFormatter.json_record()``.
104104
.. code-block:: python
105105
106106
class CustomisedJSONFormatter(json_log_formatter.JSONFormatter):
107-
def json_record(self, message, extra, record):
107+
def json_record(self, message: str, extra: dict, record: logging.LogRecord) -> dict:
108108
extra['message'] = message
109109
extra['user_id'] = current_user_id()
110110
extra['ip'] = current_ip()
111+
112+
# Include builtins
113+
extra['level'] = record.levelname
114+
extra['name'] = record.name
115+
111116
if 'time' not in extra:
112117
extra['time'] = django.utils.timezone.now()
118+
119+
if record.exc_info:
120+
extra['exc_info'] = self.formatException(record.exc_info)
121+
113122
return extra
114123
115124
Let's say you want ``datetime`` to be serialized as timestamp.

0 commit comments

Comments
 (0)