Django-Requestlog
Middleware who logs each request with their headers and the body into to PostgreSQL for diagnostic purposes.
Why Logging to the database?
Logging to the database instead of to a logfile has the advantage that it can be searched by people not having access to the server logs. Of course this only works for low traffic sites. And I recommend to purge those logs regularly with the provided manage command or celery task.
What is logged?
The log is written to the table requestlog_requestlog.
- timestamp
- client IP address
- django user-id
- method
- URL
- header fields
- cookies
- query parameter
- POST body
- HTTP status code
- the first 1024 of the response
Credits
Based on https://github.com/ASKBOT/django-request-logging
Settings
Request logging has to be explicitely enabled (for performance reasons):
REQUEST_LOGGING_ENABLED = True
You can ask the service to ignore certain fields from the querystring and the header. You do this by setting
the name of the fields in the Django settings variable REQUEST_LOGGING_HIDE_PARAMETERS. For example like this:
REQUEST_LOGGING_HIDE_PARAMETERS = [ 'HTTP_AUTHORIZATION', 'password' ]
Filter certain IPs (e.g. internal Kubernetes health check requests)
REQUEST_LOGGING_IGNORE_IPS = [ '10.2.3.4' ]
Filter certain paths by Regex (including query string):
REQUEST_LOGGING_IGNORE_PATHS = [ '/admin/login' ]
Client IP behind proxies
By default the client IP is the leftmost entry of the X-Forwarded-For header. The client sets that
entry itself, so it can be spoofed. If your app runs behind proxies, tell the middleware how many
entries they append and it logs the entry they wrote instead:
REQUEST_LOGGING_NUM_PROXIES = 1
None(default): use the leftmost entry.0: ignoreX-Forwarded-Forand useREMOTE_ADDR.n: use the n-th entry from the right. This is usually the number of proxies, but count what your infrastructure actually appends: a Google Cloud load balancer adds the client IP and its own address, so it needs2.
REMOTE_ADDR is used instead whenever the header is missing, has fewer than n entries or the
selected entry is not a valid IP address (e.g. localhost, or an entry with a port like 1.2.3.4:5678).
REQUEST_LOGGING_IGNORE_IPS is matched against the same IP. With the default, a client can therefore
keep its requests out of the log by sending an ignored IP in X-Forwarded-For; setting
REQUEST_LOGGING_NUM_PROXIES prevents that.
Purge old entries
You can use the following management command which deletes entries older than 3 days:
./manage.py requestlog_purge
Or you trigger the task with Celery beat by adding a shared task to your projects task list:
In your settings:
CELERY_BEAT_SCHEDULE = {
...
'requestlog.tasks.delete_old_requestlog_entries': {
'task': 'requestlog.tasks.delete_old_requestlog_entries',
'schedule': crontab(hour=2, minute=0)
'args': (30,) # This is the number of days to keep the entries
},
}
Metadata
Release files for django-requestlog 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_requestlog-1.2.0.tar.gz | 10.8 kB | Without provenance | Details for django_requestlog-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_requestlog-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for django_requestlog-1.2.0-py3-none-any.whl |
Total release size: 25.2 kB
Release files / django_requestlog-1.2.0.tar.gz
| Download URL | django_requestlog-1.2.0.tar.gz |
|---|---|
| Size | 10.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cad1523b6826110efca86f4b5a779caa7a8b9aaec5ea5a4a17d70024da57d724
|
|
BLAKE2b-256 checksum How to use checksums |
e2513cc2566755183dc8319685d6313be34e621f982f6c9d0ae3cdb2fa8c26a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Release files / django_requestlog-1.2.0-py3-none-any.whl
| Download URL | django_requestlog-1.2.0-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
592c7e9bc0b5676c140eb4dcd8e0e4ae06407d2a0d7d78fc270935821f1b16d0
|
|
BLAKE2b-256 checksum How to use checksums |
72d7e35575bf401afaa925e0f30268e82cc1bb862eb4a009d12cb4d767beebb6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.2
|
Security for django-requestlog 1.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.