Skip to main content

Django loggable util

An utility to create logs for request and response while keeping business code clean for class based views.

Motivation

By using generic view, we can write a view as concise as this:

class SomeModelCreateView(LoginRequiredMixin, CreateView):
    model = SomeModel

As we can see there is no place where we can write logger.info(...). It won't be pretty to override some methods in the view just for printing logs. It would make sense if there is already some overridden method in the view, then we could've put the logger method there. That's why this package is created to quickly enable request and response logs for class based views.

Installation

pip install djang-loggable-util

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 this package:

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!

Metadata

Release files for django-loggable-util 0.0.4

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.4
File Size Uploaded Provenance
django_loggable_util-0.0.4.tar.gz 3.7 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 8.6 kB

Release files / django_loggable_util-0.0.4.tar.gz

Download URL django_loggable_util-0.0.4.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
50501aeb2c465810f6febf80c680ef647d9ca4bb4944cbd812da0c3ff2604088
BLAKE2b-256 checksum
How to use checksums
8b647f3ff634b7c0652731d2b62b81f9f6093b696337a756b0d0cd428ee52399
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.4-py3-none-any.whl

Download URL django_loggable_util-0.0.4-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a7771dac201f6cafbfddc75776e13d5bd071fd9e33ab92d79a75592938a66ce8
BLAKE2b-256 checksum
How to use checksums
cc23a00451012d063f8932cb93bc1406abddbf322d2f3f3f51c97fca93b2b1fc
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

Security for django-loggable-util 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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