Graylog middleware for Django.
Project description
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 endpoint to send GELF logs to. For example,http://yourserver:12201/gelf
orudp://yourserver:12201
.GRAYLOG_NODE
- The middleware sends a_node
field that defaults tosocket.gethostname
. Set this to override it.GRAYLOG_LEVEL
- The defaultlevel
to send for log entries. Defaults to 6 (INFO).GRAYLOG_TIMEOUT
- Timeout (in seconds) for sending log entries to Graylog. Defaults to0.25
seconds.GRAYLOG_FIELDS
- Extra fields to send for each request (not prefixed with underscores). Defaults to{}
.GRAYLOG_HEADERS
-True
to include all HTTP request headers (except sensitive headers likeAuthorization
andCookie
- see below), otherwise a list of headers to be included. Defaults to[]
.GRAYLOG_EXCLUDE_HEADERS
- A list of headers to exclude whenGRAYLOG_HEADERS
isTrue
. Defaults to["authorization", "cookie", "proxy-authorization"]
.GRAYLOG_USER_AGENT
-True
to parse out User-Agent header into separate fields using ua_parser (default isFalse
).GRAYLOG_REFERER
-True
to parse out the referer domain (default isFalse
) into a separate field.GRAYLOG_TIMING
-True
to include request timing information (the default),False
to disable.
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)
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
Built Distribution
Hashes for django_graylog-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cc5ce8c7abecafee49a184c9e18676f99c5092a99f9c864d330c67d81e19666 |
|
MD5 | f9546015c2b623627ee7a463943a07eb |
|
BLAKE2b-256 | 35f7e3cb08bfba1f0a6a007d80840aacc1f1c19a0d75c220d296ebb140a5bdfa |