Skip to content

Commit

Permalink
Merge pull request #14 from wulftone/patch-1
Browse files Browse the repository at this point in the history
Add builtins example to README
  • Loading branch information
marselester authored Feb 6, 2020
2 parents f078b11 + 0a43fe0 commit 47c1fb2
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,21 @@ To do so you should override ``JSONFormatter.json_record()``.
.. code-block:: python
class CustomisedJSONFormatter(json_log_formatter.JSONFormatter):
def json_record(self, message, extra, record):
def json_record(self, message: str, extra: dict, record: logging.LogRecord) -> dict:
extra['message'] = message
extra['user_id'] = current_user_id()
extra['ip'] = current_ip()
# Include builtins
extra['level'] = record.levelname
extra['name'] = record.name
if 'time' not in extra:
extra['time'] = django.utils.timezone.now()
if record.exc_info:
extra['exc_info'] = self.formatException(record.exc_info)
return extra
Let's say you want ``datetime`` to be serialized as timestamp.
Expand Down

0 comments on commit 47c1fb2

Please sign in to comment.