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:
parent
b5ed197568
commit
26ca363b0e
6 changed files with 95 additions and 2 deletions
|
|
@ -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': {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue