Reference

Public API documentation.

Formatter

class log_outgoing_requests.formatters.HttpFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)

Display request and response (meta) details of python requests library log records.

Depending on the configuration, either only the metadata or metadata + body of requests and matching responses is emitted.

Metadata:

  • HTTP method

  • Request URL

  • Request headers (masking auth details)

  • Response status

  • Response reason

  • Response headers

Handler

class log_outgoing_requests.handlers.DatabaseOutgoingRequestsHandler(level=0)

Save the log record to the database if conditions are met.

The handler checks if saving to the database is desired. If not, nothing happens. Next, request and response body are each checked if:

  • saving to database is desired

  • the content type is appropriate

  • the size of the body does not exceed the configured treshold

If any of the conditions don’t match, then the body is omitted.

Settings

class log_outgoing_requests.conf.LogOutgoingRequestsConf(**kwargs)

Settings for django-log-outgoing-requests.

To override a setting, prefix it with LOG_OUTGOING_REQUESTS_ in your own settings file.

CONTENT_TYPES = [ContentType(pattern='application/json', default_encoding='utf-8'), ContentType(pattern='application/soap+xml', default_encoding='utf-8'), ContentType(pattern='application/xml', default_encoding='utf-8'), ContentType(pattern='text/xml', default_encoding='iso-8859-1'), ContentType(pattern='text/*', default_encoding='utf-8')]

Allowlist of content types for which the body may be saved to the database.

Use log_outgoing_requests.datastructures.ContentType to configure this setting.

DB_SAVE = True

Whether request logs should be saved to the database.

This can be overridden at runtime via configuration in the admin.

DB_SAVE_BODY = True

Whether request/response bodies should be saved to the database.

This can be overridden at runtime via configuration in the admin.

EMIT_BODY = True

Whether request/response body may be emitted in the logs.

MAX_AGE = 1

The maximum age (in days) of request logs, after which they are deleted (via a Celery task, Django management command, or the like).

MAX_CONTENT_LENGTH = 524288

The maximum size of request/response bodies for saving to the database, in bytes.

If the body is larger than this treshold, the log record will still be saved to the database, but the body will be missing.

RESET_DB_SAVE_AFTER = 60

If the config has been updated, reset the database logging after the specified number of minutes.

To protect against unintended logging of potentially sensitive data after debugging, this helps in resetting the “save to DB” configuration option. It resets back to “use the default from settings”.

If the value is falsy (including zero), then no reset takes place at all.

Note

this requires Celery to be installed, an optional dependency.