When using Django as a web service framework, the package django-log-request-id
can be used to parse and log request IDs.
Settings
MIDDLEWARE_CLASSES = (
'log_request_id.middleware.RequestIDMiddleware',
# ... other middleware goes here
)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'request_id': {
'()': 'log_request_id.filters.RequestIDFilter'
}
},
'formatters': {
'standard': {
'format': '%(levelname)-8s [%(asctime)s] [%(request_id)s] %(name)s: %(message)s'
},
},
'handlers': {
'console': {
'level': 'DEBUG',
'class': 'logging.StreamHandler',
'filters': ['request_id'],
'formatter': 'standard',
},
},
'loggers': {
'myapp': {
'handlers': ['console'],
'level': 'DEBUG',
'propagate': False,
},
}
}