1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-12-03 01:16:10 +00:00

feat(logs): each log line names its request, user and client address

A request gets nginx's $request_id (or a new one when it comes without a
valid one) and sends it back in X-Request-ID. The app log's lines carry
the logger, process and thread, the request ID, the signed-in user and the
client address; gunicorn's access lines carry the client address from
X-Real-IP and the same request ID, so the two logs can be joined.
This commit is contained in:
catborise 2026-11-05 14:36:58 +03:00
parent b5ed197568
commit 26ca363b0e
6 changed files with 95 additions and 2 deletions

View file

@ -87,6 +87,7 @@ INSTALLED_APPS = [
]
MIDDLEWARE = [
"webvirtcloud.middleware.RequestIdMiddleware",
"django.middleware.security.SecurityMiddleware",
"whitenoise.middleware.WhiteNoiseMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
@ -248,9 +249,13 @@ LOGGING = {
'disable_existing_loggers': False,
'formatters': {
'standard': {
'format': '[%(asctime)s] %(levelname)s: %(message)s'
'format': '[%(asctime)s] %(levelname)s %(name)s [%(process)d %(threadName)s] '
'%(request_id)s %(user)s %(ip)s: %(message)s'
},
},
'filters': {
'request': {'()': 'webvirtcloud.log_context.RequestFilter'},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
@ -263,6 +268,7 @@ LOGGING = {
'maxBytes': 10 * 1024 * 1024,
'backupCount': 5,
'formatter': 'standard',
'filters': ['request'],
},
},
'loggers': {