Django middleware that logs http request body.
Project description
django-request-logging
==========================
Plug django-request-logging into your Django project and you will have intuitive and color coded request/response payload logging, for both web requests and API requests. Supports Django 1.8+.
## Installing
```bash
$ pip install django-request-logging
```
Then add ```request_logging.middleware.LoggingMiddleware``` to your ```MIDDLEWARE```.
For example:
```python
MIDDLEWARE = (
...,
'request_logging.middleware.LoggingMiddleware',
...,
)
```
And configure logging in your app:
```python
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.request': {
'handlers': ['console'],
'level': 'DEBUG', # change debug level as appropiate
'propagate': False,
},
},
}
```
## Details
Most of times you don't have to care about these details. But in case you need to dig deep:
* All logs are configured using logger name "django.request".
* If HTTP status code is between 400 - 599, URIs are logged at ERROR level, otherwise they are logged at INFO level.
* If HTTP status code is between 400 - 599, data are logged at ERROR level, otherwise they are logged at DEBUG level.
See `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL` setting to override this.
A `no_logging` decorator is included for views with sensitive data.
## Django settings
You can customized some behaves of django-request-logging by following settings in Django `settings.py`.
### REQUEST_LOGGING_DATA_LOG_LEVEL
By default, data will log in DEBUG level, you can change to other valid level (Ex. logging.INFO) if need.
### REQUEST_LOGGING_ENABLE_COLORIZE
If you want to log into log file instead of console, you may want to remove ANSI color. You can set `REQUEST_LOGGING_ENABLE_COLORIZE=False` to disable colorize.
### REQUEST_LOGGING_DISABLE_COLORIZE (Deprecated)
This legacy setting will still available, but you should't use this setting anymore. You should use `REQUEST_LOGGING_ENABLE_COLORIZE` instead.
We keep this settings for backward compatibility.
### REQUEST_LOGGING_MAX_BODY_LENGTH
By default, max length of a request body and a response content is cut to 50000 characters.
### REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL
By default, HTTP status codes between 400 - 499 are logged at ERROR level. You can set `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL=logging.WARNING` (etc) to override this.
If you set `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL=logging.INFO` they will be logged the same as normal requests.
==========================
Plug django-request-logging into your Django project and you will have intuitive and color coded request/response payload logging, for both web requests and API requests. Supports Django 1.8+.
## Installing
```bash
$ pip install django-request-logging
```
Then add ```request_logging.middleware.LoggingMiddleware``` to your ```MIDDLEWARE```.
For example:
```python
MIDDLEWARE = (
...,
'request_logging.middleware.LoggingMiddleware',
...,
)
```
And configure logging in your app:
```python
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
},
'loggers': {
'django.request': {
'handlers': ['console'],
'level': 'DEBUG', # change debug level as appropiate
'propagate': False,
},
},
}
```
## Details
Most of times you don't have to care about these details. But in case you need to dig deep:
* All logs are configured using logger name "django.request".
* If HTTP status code is between 400 - 599, URIs are logged at ERROR level, otherwise they are logged at INFO level.
* If HTTP status code is between 400 - 599, data are logged at ERROR level, otherwise they are logged at DEBUG level.
See `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL` setting to override this.
A `no_logging` decorator is included for views with sensitive data.
## Django settings
You can customized some behaves of django-request-logging by following settings in Django `settings.py`.
### REQUEST_LOGGING_DATA_LOG_LEVEL
By default, data will log in DEBUG level, you can change to other valid level (Ex. logging.INFO) if need.
### REQUEST_LOGGING_ENABLE_COLORIZE
If you want to log into log file instead of console, you may want to remove ANSI color. You can set `REQUEST_LOGGING_ENABLE_COLORIZE=False` to disable colorize.
### REQUEST_LOGGING_DISABLE_COLORIZE (Deprecated)
This legacy setting will still available, but you should't use this setting anymore. You should use `REQUEST_LOGGING_ENABLE_COLORIZE` instead.
We keep this settings for backward compatibility.
### REQUEST_LOGGING_MAX_BODY_LENGTH
By default, max length of a request body and a response content is cut to 50000 characters.
### REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL
By default, HTTP status codes between 400 - 499 are logged at ERROR level. You can set `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL=logging.WARNING` (etc) to override this.
If you set `REQUEST_LOGGING_HTTP_4XX_LOG_LEVEL=logging.INFO` they will be logged the same as normal requests.
Project details
Release history Release notifications | RSS feed
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
Close
Hashes for django-request-logging-0.6.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 94f4452e00a0927f514e80dedb549e6354651628b2fb9bc42b7b1b2b3d95ee27 |
|
MD5 | fd2f5b85c476b70394db5f7ca5fe362b |
|
BLAKE2b-256 | f1cf24253a844d064cd8f6039f0f559cf5db31c9b01d2254f31f42f019a151c9 |
Close
Hashes for django_request_logging-0.6.6-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c82e2331af2b7eb76bcf6783c855ec591088206b944c4a1088098c7d8d5dffb |
|
MD5 | 0659999752108908da257196dbb15767 |
|
BLAKE2b-256 | 09a4369f43005c6035db50e9810dea55435093ef475f094b2bf1b55caa78fe90 |