django-requestlogging
This package provides a logging filter and middleware to add information about the current request to the logging record.
Installation and Usage
Install the package, add django_requestlogging to settings.INSTALLED_APPS, add django_requestlogging.middleware.LogSetupMiddleware to settings.MIDDLEWARE_CLASSES, and add django_requestlogging.logging_filters.RequestFilter as a logging filter. See below for an example logging configuration.
The filter adds information about the current request to the logging record. The following keys can be substituted in the logging formatter string:
- http_user_agent
The user agent string, provided by the client.
- path_info
The requested HTTP path.
- remote_addr
The remote IP address.
- request_method
The HTTP request method (e.g. GET, POST, PUT, DELETE, etc.)
- server_protocol
The server protocol (e.g. HTTP, HTTPS, etc.)
- username
The username for the logged-in user.
If any of this information cannot be extracted from the current request (or there is no current request), a hyphen '-' is substituted as a placeholder.
Logging Configuration Example
This logging configuration can be added to your DJANGO_SETTINGS_MODULE. It adds an unbound RequestFilter, which will be bound to the current request by the middleware and then unbound again at response time.
LOGGING = {
'filters': {
# Add an unbound RequestFilter.
'request': {
'()': 'django_requestlogging.logging_filters.RequestFilter',
},
},
'formatters': {
'request_format': {
'format': '%(remote_addr)s %(username)s "%(request_method)s '
'%(path_info)s %(server_protocol)s" %(http_user_agent)s '
'%(message)s %(asctime)s',
},
},
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'filters': ['request'],
'formatter': 'request_format',
},
},
'loggers': {
'myapp': {
# Add your handlers that have the unbound request filter
'handlers': ['console'],
# Optionally, add the unbound request filter to your
# application.
'filters': ['request'],
},
},
}
Metadata
Release files for django-requestlogging 1.0.1
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-requestlogging-1.0.1.tar.gz | 7.2 kB | Without provenance | Details for django-requestlogging-1.0.1.tar.gz |
Release files / django-requestlogging-1.0.1.tar.gz
| Download URL | django-requestlogging-1.0.1.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c97af5a4097a4810b73ed05b26e6667414233151c950a9cd6528adadc84044dc
|
|
BLAKE2b-256 checksum How to use checksums |
481b38da05706cba8a0b2b5fdbe97367df519bc4f01f015ed777b56adcaedbe9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-requestlogging 1.0.1
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.