Skip to main content

django-requestlogging

Latest Version Test/build status Code coverage

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'],
        },
    },
}

Release files for django-requestlogging-redux 1.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-requestlogging-redux 1.2.1
File Size Uploaded
django-requestlogging-redux-1.2.1.tar.gz 8.0 kB Details

Release files / django-requestlogging-redux-1.2.1.tar.gz

Download URL django-requestlogging-redux-1.2.1.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e672c65a58c647c2142165ce872eaac2fd26ddb997f9eb20b270cd78221c29b3
BLAKE2b-256 checksum
How to use checksums
afd3c52922bf8a9abc0e7c848bab899f46cbb982ab7d68d910b6aa8547c6bd07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.2.1 This release

1 release file

1.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page