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.
- List of keys in request/response data which will be replaced with
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_requestlogs-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f50144b969e068db21029101560c9db32ddcee2ee7bb2fc9298cb34d8aa652a |
|
MD5 | 92db579a0c12d1027e93c217809dffd3 |
|
BLAKE2b-256 | d4f2b28898f342bcd280e763368205b0476bcffe0b14ae1761be92f96bf058b7 |