Middleware that makes a request GUID available from anywhere and injects it into your logs.
Project description
GUID injection for Django
Django GUID attaches a GUID to the local thread of a request. The GUID is accessible from anywhere within the application throughout a request, making it possible to inject the GUID into the logs.
Free software: BSD License
Homepage: https://github.com/JonasKs/django-guid
Documentation: Incoming
Installation
Python package:
pip install django-guid
In your project’s settings.py add these settings:
Add the middleware to the middleware (To ensure the GUID to be injected in all logs, put it on top)
MIDDLEWARE = [
'django_guid.middleware.GuidMiddleware',
...
]
Add a filter to your LOGGING:
LOGGING = {
'filters': {
'correlation_id': {
'()': 'django_guid.log_filters.CorrelationId'
}
}
}
and put that filter in your handler:
'handlers': {
'console': {
'class': 'logging.StreamHandler',
'formatter': 'medium',
'filters': ['correlation_id'],
}
}
and lastly make sure we add it to the format:
'medium': {
'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s'
}
Inspired by django-log-request-id with a django-crequest approach.
Changelog
0.2.3 - 2019-12-21
Features
Added tests written in pytests, 100% codecov
Added Django2.2 and Django3 to github workflow as two steps
Improved logging
0.2.2 - 2019-12-21
Features
Removed the mandatory DJANGO_GUID settings in settings.py. Added an example project to demonstrate how to set the project up
0.2.1 - 2019-12-21
Features
Workflow added, better docstrings, easier to read flow
0.2.0 - 2019-12-21
Features
Header name and header GUID validation can be specified through Django settings
2019-12-20
Initial release
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
Hashes for django_guid-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ece3ba87f627edf1585e9b830efbfac1694a3cbef944711392c541ff62a3ef7 |
|
MD5 | 48c08b77a80638c5938c0581b4aeb8ff |
|
BLAKE2b-256 | 2cf595e9c712308a378c94f16fbec580d8bc691d738ba2a3a314548a422269c1 |