Skip to main content

A Python logging filter for Django user attributes.

Project description

django-user-trace

A Python logging filter for Django user attributes

Build Coverage Python PyPI

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.

Visit the documentation.

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

Supports

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


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-2.0.0.tar.gz (13.9 kB view details)

Uploaded Source

Built Distribution

django_user_trace-2.0.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file django_user_trace-2.0.0.tar.gz.

File metadata

  • Download URL: django_user_trace-2.0.0.tar.gz
  • Upload date:
  • Size: 13.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure

File hashes

Hashes for django_user_trace-2.0.0.tar.gz
Algorithm Hash digest
SHA256 750baad616d80e42003d5d2037b612c28c1f0b99233ea46d36b29ac68b395414
MD5 879d9bd552f6d69e2b09ec7bd8365de9
BLAKE2b-256 c26e872047030ac4a22172ce6135c13c068f46b73376d0e936f033753039de4d

See more details on using hashes here.

File details

Details for the file django_user_trace-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_user_trace-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure

File hashes

Hashes for django_user_trace-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 844663cde15f2bdfc92b8af198ddee384a59d2d23787dec64dc08110d184b78b
MD5 b262abf674ecd79d12020edeba7ba1c0
BLAKE2b-256 71f7a4dd00023cf9b1979c8832bbb153d015cd8016d9e04337688046b2b13ada

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page