Skip to main content

Audit logging for Django and Django Rest Framework

Project description

django-requestlogs

django-requestlogs is a package providing middleware and other helpers for audit logging.

Installation

Install using pip:

pip install django-requestlogs

Add 'requestlogs.middleware.RequestLogsMiddleware' to MIDDLEWARE settings.

MIDDLEWARE = [
    ...
    'requestlogs.middleware.RequestLogsMiddleware',
]

This will start storing the request logs using the default STORAGE_CLASS, which in fact just uses Python logger named requestlogs. Now you can, for example, redirect these logs to a file with the following LOGGING configuration:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'requestlogs_to_file': {
            'level': 'INFO',
            'class': 'logging.FileHandler',
            'filename': '/tmp/requestlogs.log',
        },
    },
    'loggers': {
        'requestlogs': {
            'handlers': ['requestlogs_to_file'],
            'level': 'INFO',
        },
    },
}

Settings

Requestlogs can be customized using Django settings. The following shows the default values for the available settings:

REQUESTLOGS = {
    'STORAGE_CLASS': 'requestlogs.storages.LoggingStorage',
    'ENTRY_CLASS': 'requestlogs.entries.RequestLogEntry',
    'SECRETS': ['password', 'token'],
    'ATTRIBUTE_NAME': '_requestlog',
}
  • STORAGE_CLASS
    • Path to the Python class which will handle storing the log entries. Override this if you only need to reimplement the storage mechanism. This may be the case e.g. when choosing what data to store.
  • ENTRY_CLASS
    • Path to the Python class which handles the construction of the complete requestlogs entry. Override this for full customization of the requestlog entry behaviour.
  • SECRETS
    • List of keys in request/response data which will be replaced with '***' in the stored entry.
  • ATTRIBUTE_NAME
    • django-requestlogs internally attaches the entry object to the Django request object, and uses this attribute name. Override if it causes collusions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-requestlogs-0.1.4.tar.gz (4.4 kB view hashes)

Uploaded Source

Built Distribution

django_requestlogs-0.1.4-py3-none-any.whl (6.8 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page