A middleware to log the requests and responses using loguru.
Project description
Django Loguru
The extension was based on another one and added some extra flavours. One of the biggest problems with the apps is the logging and that can be messy sometimes.
Since this serves as a middleware, it only depends on django (including django rest framework).
Documentation: https://tarsil.github.io/django-loguru/
Table of Contents
Requirements
- Python >= 3.7
- Django >= 3.1
Installation
pip install django-loguru- Add
django_logurutoINSTALLED_APPSsettings.
INSTALLED_APPS = [
...
'django_loguru'
]
- Add
DJANGO_LOGURU_MIDDLEWAREto your settings.
DJANGO_LOGGING_MIDDLEWARE = {
'DEFAULT_FORMAT': True,
'MESSAGE_FORMAT': "<b><green>{time}</green> <cyan>{message}</cyan></b>",
'LOG_USER': False
}
- Add
django_loguru.middleware.DjangoLoguruMiddlewareas the very last in the list ofMIDDLEWARE.
The logs should be now activated for every request/response of you application.
If you desire to override what is shown on the screen.
from django_loguru.middleware import DjangoLoguruMiddleware
class MyCustomMiddleware(DjangoLoguruMiddleware):
def __call__(self, request):
"""
Code to be executed on every request/response call.
"""
logger.info(f"URL: {request.get_raw_uri()}")
logger.info(f"Method: {request.method}")
...
...
Settings
DEFAULT_FORMAT- DefaultTrueand it will use the defaultMESSAGE_FORMAT.MESSAGE_FORMAT- Sets the format of the log messages. Defaults to<b><green>{time}</green> <blue>{message}</blue></b>. More information about your options on loguru docs.LOG_POST- Default toFalseand it won't show POST data.LOG_PUT- Default toFalseand it won't show PUT data.LOG_PATCH- Default toFalseand it won't show PATCH data.LOG_DELETE- Default toFalseand it won't show DELETE data.LOG_USER- Default toTrueand tells which user did the request/response.
License
MIT-License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_loguru-1.0.3-py3-none-any.whl.
File metadata
- Download URL: django_loguru-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31e0dcbff4c044a007956953ddd2d9b0aeb5ce6565a321120435730a3e35ab30
|
|
| MD5 |
05f043fdfe9d5b0d4db87a8551f2960a
|
|
| BLAKE2b-256 |
29cfb4fde772fcbfe63befefb75c297316ce9f6fb9543dc8968f5c929b893136
|