django-graylog
A Django middleware for logging requests to Graylog.
Installation
pip install django-graylog
Using an HTTP/HTTPS requires the requests
module, which can be included with pip install django-graylog[http].
Parsing user agents requires the ua_parser
module, which can be included with pip install django-graylog[ua].
All optional libraries may be included using pip install django-graylog[all].
Configuration
Simply add django_graylog.GraylogMiddleware to your MIDDLEWARE setting, after
django.middleware.common.CommonMiddleware. By default, the middleware does nothing
unless GRAYLOG_ENDPOINT is set (see below).
Settings
GRAYLOG_ENDPOINT- An HTTP, HTTPS, UDP, or TCP endpoint to send GELF logs to. For example:http://yourserver:12201/gelfudp://yourserver:12201tcp://yourserver:12201
GRAYLOG_NODE- The middleware sends a_nodefield that defaults tosocket.gethostname. Set this to override it.GRAYLOG_LEVEL- The defaultlevelto send for log entries. Defaults to 6 (INFO).GRAYLOG_TIMEOUT- Timeout (in seconds) for sending log entries to Graylog. Defaults to0.25seconds.GRAYLOG_FIELDS- Extra fields to send for each request (not prefixed with underscores). Defaults to{}.GRAYLOG_HEADERS-Trueto include all HTTP request headers (except sensitive headers likeAuthorizationandCookie- see below), otherwise a list of headers to be included. Defaults to[].GRAYLOG_EXCLUDE_HEADERS- A list of headers to exclude whenGRAYLOG_HEADERSisTrue. Defaults to["authorization", "cookie", "proxy-authorization"].GRAYLOG_USER_AGENT-Trueto parse out User-Agent header into separate fields using ua_parser (default isFalse).GRAYLOG_REFERER-Trueto parse out the referer domain (default isFalse) into a separate field.GRAYLOG_USERNAME-Trueto includerequest.user.get_username()(default isFalse).GRAYLOG_TIMING-Trueto include request timing information (the default),Falseto disable.GRAYLOG_FILTERS- A dictionary of filters to exclude records from being logged. Each key is a field name, and each value is a list of regegular expressions to exclude. For example:{"host": [r"media.example.com"]}- Skips logging of requests to themedia.example.comdomain.{"path": [r"^/_"]}- Skips logging of requests to paths starting with_.{"ip": "192\.168\."}- Skips logging of requests from192.168.*addresses. Using a string instead of a list works for a single regular expression.
GRAYLOG_EXCEPTION_MESSAGES- Whether to include exception messages in data sent to Graylog. Setting toFalsewill strip the last line from stack traces (in case the line includes a literal message), and not send the_exception_messagefield. Defaults toTrue.GRAYLOG_FACILITY- Sent as_facility, and used as the default logger name for logging messages sent viarequest.graylog.GRAYLOG_TIMESTAMP- Whether to include atimestampfield in data sent to Graylog. Setting toFalsemeans Graylog will infer the current time when it receives log entries. Defaults toTrue.GRAYLOG_IP- Whether to include the IP address of requests. Defaults toTrue.
Advanced Usage
In addition to the standard logging middleware, django_graylog installs an object on
your request objects (request.graylog) that has standard logging methods for recording
per-request logs. You may also set custom keys on this object
(request.graylog["key"] = "value") that will be included in log entries. For example:
def homepage(request):
request.graylog["user"] = request.user.user_name
request.graylog.info("Rendered homepage for {user}", user=request.user.user_name)
If you want standard Python logging calls during a request to be logged into Graylog as
well, django_graylog comes with a GraylogRequestHandler logging handler that tracks
the current request and associates logging to it.
Metadata
Release files for django-graylog 0.9.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_graylog-0.9.0.tar.gz | 7.2 kB | Without provenance | Details for django_graylog-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_graylog-0.9.0-py3-none-any.whl | Python 3 | none | any | Details for django_graylog-0.9.0-py3-none-any.whl |
Total release size: 14.6 kB
Release files / django_graylog-0.9.0.tar.gz
| Download URL | django_graylog-0.9.0.tar.gz |
|---|---|
| Size | 7.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f123d6039bbe13b223975758dcabea507689da361bcbb822699619965c5f55b3
|
|
BLAKE2b-256 checksum How to use checksums |
92c67ce0144c4f4e8b31d441b7f8e074dee3508a758832095feabfd7e19fba0e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / django_graylog-0.9.0-py3-none-any.whl
| Download URL | django_graylog-0.9.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ee89afb79791ff415f9ba4df41001f8ae1e3c5dc4438c578053eb338be77caa
|
|
BLAKE2b-256 checksum How to use checksums |
7638dcbd4a3dc47046078909f7b464559aeb81c5e414c0bdfce326b38ea4b327
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for django-graylog 0.9.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.