Metadata-Version: 2.1
Name: django-guid
Version: 0.2.2
Summary: Middleware that makes a request GUID available from anywhere and injects it into your logs.
Home-page: https://github.com/JonasKs/django-guid
Author: Jonas Krüger Svensson
Author-email: jonas-ks@hotmail.com
License: BSD
Download-URL: https://pypi.python.org/pypi/django-guid
Keywords: django,logging,request,web,uuid,guid
Platform: OS Independent
Classifier: Development Status :: 5 - Production/Stable
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Web Environment
Classifier: Framework :: Django
Classifier: Framework :: Django :: 2.2
Classifier: Framework :: Django :: 3.0
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: Dynamic Content
Classifier: Topic :: Internet :: WWW/HTTP :: WSGI
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Dist: Django (>=2.2)

GUID injection for Django
=========================

.. image:: https://img.shields.io/pypi/v/django-guid.svg
    :target: https://pypi.python.org/pypi/django-guid
.. image:: https://img.shields.io/pypi/pyversions/django-guid.svg
    :target: https://pypi.python.org/pypi/django-guid#downloads
.. image:: https://img.shields.io/pypi/djversions/django-guid.svg
    :target: https://pypi.python.org/pypi/django-guid

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)

.. code-block:: python

    MIDDLEWARE = [
        'django_guid.middleware.GuidMiddleware',
        ...
     ]


Add a filter to your ``LOGGING``:

.. code-block:: python

    LOGGING = {
        'filters': {
            'correlation_id': {
                '()': 'django_guid.log_filters.CorrelationId'
            }
        }
    }


and put that filter in your handler:

.. code-block:: python

    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'formatter': 'medium',
            'filters': ['correlation_id'],
        }
    }

and lastly make sure we add it to the format:

.. code-block:: python

    'medium': {
        'format': '%(levelname)s %(asctime)s [%(correlation_id)s] %(name)s %(message)s'
    }

Inspired by `django-log-request-id <https://github.com/dabapps/django-log-request-id>`_ with a
`django-crequest <https://github.com/Alir3z4/django-crequest>`_ approach.


Changelog
=========

`0.2.0`_ - 2019-12-21
---------------------

**Features**

* Header name and header GUID validation can be specified through Django settings.

2019-12-20
------------------

* Initial release


.. _0.2.0: https://github.com/jonasks/django-guid/compare/0.1.2...0.2.0


