Django - Unique Unique Identifier

I assign a unique identifier to each incoming request and want it to be automatically included in the logs when logging is performed (without explicitly including it in all places). I use middleware to create and store this unique identifier in a local thread.

I want to change the Django logging format to include this unique identifier directly:

LOGGING = { ... 'formatters': { 'full': { 'format': '%(asctime)s %(levelname)s %(name)s - %(message)s', } } ... } 

How to add a unique id component to the formatter without explicitly adding it to each log statement?

+4
source share
1 answer

Use Filter : this technique is described in this post . Although this applies to IP addresses, you can also easily use the approach to register unique request identifiers.

+4
source

Source: https://habr.com/ru/post/1379090/


All Articles