Commit 83dc739c authored by Mathieu Courcelles's avatar Mathieu Courcelles

Changes Nginx and Gunicorn logging to JSON.

parent e972cf57
Pipeline #14859330 canceled with stage
......@@ -228,6 +228,10 @@ LOGGING = {
# 'filters': ['require_debug_false'],
# 'class': 'django.utils.log.AdminEmailHandler'
# },
'console': {
'class': 'logging.StreamHandler',
'formatter': 'json',
},
'sentry': {
'level': 'ERROR',
'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
......@@ -236,11 +240,17 @@ LOGGING = {
},
'loggers': {
'django': {
'handlers': ['sentry'],
'level': 'ERROR',
'handlers': ['console', 'sentry'],
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': True,
},
}
},
'formatters': {
'json': {
'()': 'pythonjsonlogger.jsonlogger.JsonFormatter',
'format': '%(asctime) %(name) %(processName) %(filename) %(funcName) %(levelname) %(lineno) %(module) %(threadName) %(message)',
},
},
}
......
......@@ -7,5 +7,6 @@ reload = False
timeout = 518400
max_requests = 50
loglevel = 'info'
loglevel = 'warning'
accesslog = '-'
access_log_format = '{"remote_address":"%(h)s","timestamp":"%(t)s","request_method":"%(m)s","url":"%(U)s","query":"%(q)s","protocol":"%(H)s","status":"%(s)s","response_length":"%(b)s","referer":"%(f)s","user_agent":"%(a)s","process_id":"%(p)s"}'
......@@ -62,6 +62,21 @@ http {
gzip_disable "MSIE [1-6]\.";
gzip_vary on;
log_format json escape=json '{ "timestamp": "$time_iso8601", '
'"remote_address": "$remote_addr", '
'"x_forwarded_for": "$http_x_forwarded_for", '
'"request_method": "$request_method", '
'"url": "$uri", '
'"query": "$query_string", '
'"protocol": "$server_protocol", '
'"status": "$status", '
'"response_length": "$body_bytes_sent", '
'"referrer": "$http_referer", '
'"request_time": "$request_time", '
'"process_id": "$pid", '
'"user_agent": "$http_user_agent" }';
upstream app_server {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response
......@@ -98,6 +113,8 @@ http {
listen 80;
server_name HOST_REPLACE nginx;
access_log /dev/stdout json;
location /static/ {
alias /usr/src/app/static_root/;
expires 1h;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment