diff --git a/README.rst b/README.rst index 35fd448..ca7d3aa 100644 --- a/README.rst +++ b/README.rst @@ -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.