Skip to main content

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!

Release files for django-loggable-util 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-loggable-util 0.0.3
File Size Uploaded
django_loggable_util-0.0.3.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-loggable-util 0.0.3
File Interpreter ABI Platform
django_loggable_util-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 8.0 kB

Release files / django_loggable_util-0.0.3.tar.gz

Download URL django_loggable_util-0.0.3.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
76cb1dae7fffcac235b232a32aa93fe30a545f26174632947252e140450aa2de
BLAKE2b-256 checksum
How to use checksums
a7566e798ae70a7f182dbd039ec5703180a3df307b51bb973b82a6e28ecdb4f4
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / django_loggable_util-0.0.3-py3-none-any.whl

Download URL django_loggable_util-0.0.3-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60f43f289552e6b1a3b3ec58c3d5d4dc902dc30ec23d45703d9ed96c219d4fe2
BLAKE2b-256 checksum
How to use checksums
5ff982bcdd9dc554011f82807a1b95deda4821d121c3ae66c2b0f2bea2b7f79b
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

0.0.4

2 release files

This release

0.0.3 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page