From a6e7c594f351c00a7c79e2f35dbceca74cfad57c Mon Sep 17 00:00:00 2001
From: Tanner Prestegard <tanner.prestegard@ligo.org>
Date: Wed, 1 May 2019 14:50:23 -0500
Subject: [PATCH] Add prefix to gunicorn and apache logging

---
 config/gunicorn_config.py | 11 ++++++++---
 docker/apache-config      |  3 +++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/config/gunicorn_config.py b/config/gunicorn_config.py
index 384525876..854ddc930 100644
--- a/config/gunicorn_config.py
+++ b/config/gunicorn_config.py
@@ -27,14 +27,19 @@ worker_class = 'sync'
 #max_requests = 0
 #max_requests_jitter = 0
 
+# Logging ---------------------------------------------------------------------
 # Access log
 accesslog = join(LOG_DIR, "gunicorn_access.log")
-access_log_format = '%(t)s %(h)s %(l)s %(u)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
+access_log_format = ('GUNICORN | %(h)s %(l)s %(u)s %(t)s '
+    '"%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"')
 
 # Error log
 errorlog = join(LOG_DIR, "gunicorn_error.log")
 loglevel = 'debug'
 capture_output = True
 
-#forwarded_allow_ips = '127.0.0.1'
-#proxy_allow_ips = '127.0.0.1'
+# Override logger class to modify error format
+from gunicorn.glogging import Logger
+class CustomLogger(Logger):
+    error_fmt = 'GUNICORN | ' + Logger.error_fmt
+logger_class = CustomLogger
diff --git a/docker/apache-config b/docker/apache-config
index 8839f4a0f..0adfebbbe 100644
--- a/docker/apache-config
+++ b/docker/apache-config
@@ -9,6 +9,9 @@ ServerName ${DJANGO_PRIMARY_FQDN}
 
   ServerAdmin cgca-admins@uwm.edu
 
+  ## Log format
+  LogFormat "APACHE | %a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\""
+
   ## Vhost docroot
   DocumentRoot "/var/www/html"
 
-- 
GitLab