Registry / web-framework / django-request-logging

django-request-logging

JSON →
library0.7.5pypypiunverified

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-logging
INSTALL
IMPORT
SIG · DJANGO-REQUEST-LOG
D
django-request-logging
web-frameworkpythonv0.7.5
Install
3.4s avg
Import
Disk
65MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.915 runs
installs and imports cleanly · install 0.0s · import 0.000s · 66.3MB
glibc
py 3.103.915 runs
installs and imports cleanly · install 3.4s · import 0.000s · 67MB
65MB installed
● package 65MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

LoggingMiddleware
from request_logging.middleware import LoggingMiddleware
from request_logging.middleware import LoggingMiddleware

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.

import logging # settings.py INSTALLED_APPS = [ # ... # 'request_logging', # Not strictly required, but can be added if you want to explicitly signal app presence # ... ] MIDDLEWARE = [ # ... other middleware 'request_logging.middleware.LoggingMiddleware', # ... other middleware ] LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'class': 'logging.StreamHandler', }, }, 'loggers': { 'django.request': { 'handlers': ['console'], 'level': 'DEBUG', # Change debug level as appropriate 'propagate': False, # Important: prevent duplication if other loggers handle 'django' }, }, 'root': { 'handlers': ['console'], 'level': 'WARNING', } } # Optional: Customize log levels for specific HTTP status codes # REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL = logging.WARNING # REQUEST_LOGGING_DATA_LOG_LEVEL = logging.INFO # REQUEST_LOGGING_ENABLE_COLORIZE = False # Disable color for file logging # Example usage in a view to disable logging from django.http import HttpResponse from request_logging.decorators import no_logging @no_logging() def sensitive_view(request): return HttpResponse("This view's requests/responses are not logged.") @no_logging(log_headers=False, log_body=False) def partially_sensitive_view(request): return HttpResponse("This view logs only metadata, no headers or body.")
Debug
Known issues
gotchaSensitive data might be logged by default. The middleware logs request and response bodies.
fix
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.
affects: All versions
gotchaIncorrect Django `LOGGING` configuration can lead to missing or duplicated logs.
fix
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.
affects: All versions
gotchaExtensive request logging, especially to a database, can impact application performance.
fix
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.
affects: All versions
gotchaThe default log levels for different HTTP status codes might be unexpected. By default, 4xx-5xx responses are logged at ERROR level, others at INFO/DEBUG.
fix
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`.
affects: All versions
Upgrade
Version history
0.7.5latest on PyPI · released Feb 23, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
16
OpenAI (training)
1
Resources
django-request-logging — pip install django-request-logging · libregistry