Skip to main content

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, or TCP endpoint to send GELF logs to. For example:
    • http://yourserver:12201/gelf
    • udp://yourserver:12201
    • tcp://yourserver:12201
  • GRAYLOG_NODE - The middleware sends a _node field that defaults to socket.gethostname. Set this to override it.
  • GRAYLOG_LEVEL - The default level to send for log entries. Defaults to 6 (INFO).
  • GRAYLOG_TIMEOUT - Timeout (in seconds) for sending log entries to Graylog. Defaults to 0.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 like Authorization and Cookie - see below), otherwise a list of headers to be included. Defaults to [].
  • GRAYLOG_EXCLUDE_HEADERS - A list of headers to exclude when GRAYLOG_HEADERS is True. Defaults to ["authorization", "cookie", "proxy-authorization"].
  • GRAYLOG_USER_AGENT - True to parse out User-Agent header into separate fields using ua_parser (default is False).
  • GRAYLOG_REFERER - True to parse out the referer domain (default is False) into a separate field.
  • GRAYLOG_USERNAME - True to include request.user.get_username() (default is False).
  • GRAYLOG_TIMING - True to include request timing information (the default), False to 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 the media.example.com domain.
    • {"path": [r"^/_"]} - Skips logging of requests to paths starting with _.
    • {"ip": "192\.168\."} - Skips logging of requests from 192.168.* addresses. Using a string instead of a list works for a single regular expression.

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

django-graylog-0.6.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

django_graylog-0.6.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file django-graylog-0.6.0.tar.gz.

File metadata

  • Download URL: django-graylog-0.6.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for django-graylog-0.6.0.tar.gz
Algorithm Hash digest
SHA256 4a95abfb9462ab41a94305a28fb8dd26e3bfca789d36cb00f3554f776fc95bdb
MD5 0f0217dd1a051956fe489ea1f6bf94d2
BLAKE2b-256 c08ee702b2b38f0e1926b0ebfcf0c0eb3e6ecba6a4d72266e1ddfd12a35563b9

See more details on using hashes here.

File details

Details for the file django_graylog-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: django_graylog-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/54.0.0 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.1

File hashes

Hashes for django_graylog-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fcc3d6febb09e0092f012933b0a83a489b725e89d6d2572745084f467545249a
MD5 e269178a6569a6bf97bb52327fe03d4c
BLAKE2b-256 0b4409072354827839d2f051d364a3ed17ab04c9bcb07d2fc5715fe24d530efb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page