Separate logging from class based view business code
Project description
Django loggable util
An utility to separate create logs for request and response while keeping business code clean for class based views.
Example usage
Import the Loggable class in your urls.py
from django-loggable-util import Loggable
Now write url configuration as this:
urlpatterns=[
...
path('someurl', Loggable(SomeCBView).as_view(),name='some-url-name'),
...
]
You can pass usual parameters like template_name etc, in as_view() function.
This will result in logs like this for every request response cycle:
INFO | 2020-08-17 09:10:12.764 | {'request': {'method': 'GET', 'path': '/someurl', 'username': 'someuser', 'params': <QueryDict: {'somekey':'someval'}>}}
INFO | 2020-08-17 09:10:12.777 | {'response': {'username': 'someuser', 'status_code': 200, 'template': ['sometemplate.html']}}
A default configuration is embedded with with library for checking if it works or not which is like this:
default_log_config = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'request_response_formatter': {
'format': '%(levelname)s | %(asctime)s.%(msecs)03d | %(message)s',
'datefmt': "%Y-%m-%d %H:%M:%S",
}
},
'handlers': {
'request_response_console': {
'level': 'INFO',
'class': 'logging.StreamHandler',
'formatter': 'request_response_formatter'
}
},
'loggers': {
'request_response': {
'handlers': ['request_response_console'],
'level': 'INFO',
'propagate': False
}
}
}
This configuration streams logs to console. When it is needed to stream logs to files or any other service,
you can add that logging configuration in settings.py and provide logger name to use for this library like this:
LOGGABLE_LOGGER='your_logger_name'
Todos
- Write Tests
- Support DRF
- Support FBV
License
MIT
Free Software, Hell Yeah!
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
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_loggable_util-0.0.3.tar.gz.
File metadata
- Download URL: django_loggable_util-0.0.3.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76cb1dae7fffcac235b232a32aa93fe30a545f26174632947252e140450aa2de
|
|
| MD5 |
71450dabf1b793084d8480438d504e2d
|
|
| BLAKE2b-256 |
a7566e798ae70a7f182dbd039ec5703180a3df307b51bb973b82a6e28ecdb4f4
|
File details
Details for the file django_loggable_util-0.0.3-py3-none-any.whl.
File metadata
- Download URL: django_loggable_util-0.0.3-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60f43f289552e6b1a3b3ec58c3d5d4dc902dc30ec23d45703d9ed96c219d4fe2
|
|
| MD5 |
28305921bf90ad3191971bc0ab401995
|
|
| BLAKE2b-256 |
5ff982bcdd9dc554011f82807a1b95deda4821d121c3ae66c2b0f2bea2b7f79b
|