Django Request Logging is a middleware for Django projects that provides intuitive and color-coded logging of HTTP request and response payloads, suitable for both web and API requests. It integrates with Django's standard logging system, allowing developers to monitor traffic and debug applications effectively. The library is currently active, with version 0.7.5 released in February 2022, and supports Django 1.8+.
pip install django-request-loggingVerified import paths — ran on the pinned version, not inferred.
To quickly set up `django-request-logging`, add `request_logging.middleware.LoggingMiddleware` to your `MIDDLEWARE` list in `settings.py`. Crucially, configure your Django `LOGGING` settings to handle the `django.request` logger. This logger is where `django-request-logging` outputs its messages. Setting `propagate: False` for `django.request` prevents log messages from being handled by parent loggers and potentially duplicated. You can also use the `@no_logging` decorator on views to control logging behavior for sensitive endpoints.
Use the `@no_logging` decorator on views handling sensitive data. For example, `@no_logging()` will disable all logging for that view, while `@no_logging(log_headers=False, log_body=False)` allows partial logging.
Ensure a handler is defined for the `django.request` logger in your `LOGGING` dictionary. Set `propagate: False` for `django.request` to prevent logs from being processed multiple times by other handlers.
While `django-request-logging` primarily logs to `StreamHandler` (console), be mindful of log levels. Consider reducing the `level` for `django.request` in production (e.g., to `INFO` or `WARNING`) or using filters to log only critical requests to avoid excessive I/O.
Adjust the `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL` and `REQUEST_LOGGING_DATA_LOG_LEVEL` settings in `settings.py` to match your desired logging verbosity for different response types. For example, `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL = logging.WARNING`.
No dependency data recorded yet.