django_dd_logger.formatters package

Submodules

django_dd_logger.formatters.datadog module

class django_dd_logger.formatters.datadog.DataDogJSONFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]

Bases: JSONFormatter

extra_from_record(record)[source]

Returns extra dict you passed to logger.

The extra keyword argument is used to populate the __dict__ of the LogRecord.

get_datadog_attributes(record)[source]

Helper to extract dd.* attributes from the log record.

get_wsgi_request()[source]
json_record(message, extra, record)[source]

Prepares a JSON payload which will be logged.

Override this method to change JSON log format.

Parameters:
  • message – Log message, e.g., logger.info(msg=’Sign up’).

  • extra – Dictionary that was passed as extra param logger.info(‘Sign up’, extra={‘referral_code’: ‘52d6ce’}).

  • recordLogRecord we got from JSONFormatter.format().

Returns:

Dictionary which will be passed to JSON lib.

to_json(record)[source]

Converts record dict to a JSON string.

It makes best effort to serialize a record (represents an object as a string) instead of raising TypeError if json library supports default argument. Note, ujson doesn’t support it. ValueError and OverflowError are also caught to avoid crashing an app, e.g., due to circular reference.

Override this method to change the way dict is converted to JSON.

django_dd_logger.formatters.datadog.get_client_ip(request)[source]
django_dd_logger.formatters.datadog.get_wsgi_request_auth(wsgi_request)[source]
django_dd_logger.formatters.datadog.get_wsgi_request_user(wsgi_request)[source]

Module contents