A Python logging filter for Django user attributes.
Project description
django-user-trace
provides a Python logging filter that
injects attributes from the currently logged in Django user.
It uses a ContextVar
to store user attributes for use on
the current thread. These are then injected into all log records via a logging
filter.
sequenceDiagram
actor User
User ->>+ django: make request
django ->>+ django.contrib.auth: AuthenticationMiddleware
django.contrib.auth ->>+ django: set `request.user`
django ->>+ django_user_trace: django_user_trace_middleware
note over django, django_user_trace: Capture relevant user attributes into a `ContextVar`
django_user_trace ->>+ django: continue
django --> logging: log message
logging ->>+ django_user_trace: get user attrs
django_user_trace -->> logging: `ContextVar` for user attrs
django ->>+ django_user_trace: signal `request_finished`
note over django, django_user_trace: Clear user attributes from the `ContextVar`
django_user_trace ->>+ django: continue
django -->> User: send response
Resources
Related Projects
Installation
Install via pip
:
pip install django-user-trace
Or, via poetry
:
poetry add django-user-trace
Contributing
Thank you for considering contributing to django-user-trace
! Please see the
Contribution Guidelines.
Security Vulnerabilities
Please review the Security Policy on how to report security vulnerabilities.
Licence
django-user-trace
is open-sourced software licenced under the
MIT licence.
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
django_user_trace-1.0.0.tar.gz
(11.2 kB
view hashes)
Built Distribution
Close
Hashes for django_user_trace-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0437a99b0ab0c356dfa9d37aeb8e2ef9756590bd99015217027529e833f724a |
|
MD5 | 55416090a93494e50362fd493a3d1195 |
|
BLAKE2b-256 | 1c2eb46cf3082de686645a76f7f3e88cbbd31b52faeaea7dd86fc4a32f252818 |