From 78a96999ac3f6f7b783c26f660db1f1542d5ad90 Mon Sep 17 00:00:00 2001
From: jurgenhaas <juergen@paragon-es.de>
Date: Fri, 3 Mar 2017 09:28:08 +0100
Subject: [PATCH] ansible-roles/apache#6 Define ErrorLogFormat

---
 templates/default     | 10 ++++++++--
 templates/default-ssl | 31 ++++++++++++++++++-------------
 2 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/templates/default b/templates/default
index 5eac578..a77f7bc 100644
--- a/templates/default
+++ b/templates/default
@@ -9,9 +9,15 @@
     Options -MultiViews
   </Directory>
 
-  ErrorLog /var/log/apache2/error.log
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
   LogLevel warn
-  CustomLog /var/log/apache2/access.log combined
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/error.log
+  CustomLog ${APACHE_LOG_DIR}/access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/access.log proxy env=forwarded
 </VirtualHost>
 
 <VirtualHost *:80>
diff --git a/templates/default-ssl b/templates/default-ssl
index 759e843..20ba9ab 100644
--- a/templates/default-ssl
+++ b/templates/default-ssl
@@ -57,14 +57,15 @@
   ErrorDocument 500 /500.html
   ErrorDocument 503 /deploy.html
 
-  # It is assumed that the log directory is in /var/log/httpd.
-  # For Debian distributions you might want to change this to
-  # /var/log/apache2.
-  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
-  ErrorLog ${APACHE_LOG_DIR}/gitlab_ssl_error.log
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl_forwarded.log common_forwarded
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl_access.log combined env=!dontlog
-  CustomLog ${APACHE_LOG_DIR}/gitlab_ssl.log combined
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
+  LogLevel warn
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/gitlab-error.log
+  CustomLog ${APACHE_LOG_DIR}/gitlab-access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/gitlab-access.log proxy env=forwarded
 </VirtualHost>
 
 <VirtualHost _default_:443>
@@ -116,9 +117,13 @@
     ProxyPassReverseCookieDomain 127.0.0.1 {{ mattermost_domain }}
   </Location>
 
-  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
-  ErrorLog /var/log/apache2/mattermost_error.log
-  CustomLog /var/log/apache2/mattermost_forwarded.log common_forwarded
-  CustomLog /var/log/apache2/mattermost_access.log combined env=!dontlog
-  CustomLog /var/log/apache2/mattermost.log combined
+  SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
+  LogLevel warn
+{% if apache_version == '2.4' %}
+  ErrorLogFormat "[%{u}t] [%l] [pid %P] [client\ %{X-Forwarded-For}i] %M% ,\ referer:\ %{Referer}i"
+{% endif %}
+  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
+  ErrorLog ${APACHE_LOG_DIR}/mattermost-error.log
+  CustomLog ${APACHE_LOG_DIR}/mattermost-access.log combined env=!forwarded
+  CustomLog ${APACHE_LOG_DIR}/mattermost-access.log proxy env=forwarded
 </VirtualHost>
-- 
GitLab