Use the apache 2.4 ErrorLogFormat directive
Use the new ErrorLogFormat directive to make the Keystone logs
under Apache to look like the standard oslo log format.
Change-Id: Ie823abf2fa06b8ce22027c21bef455808a4a768e
diff --git a/files/apache-keystone.template b/files/apache-keystone.template
index a9d9cc3..e7b2157 100644
--- a/files/apache-keystone.template
+++ b/files/apache-keystone.template
@@ -6,6 +6,7 @@
WSGIProcessGroup keystone-public
WSGIScriptAlias / %PUBLICWSGI%
WSGIApplicationGroup %{GLOBAL}
+ %ERRORLOGFORMAT%
ErrorLog /var/log/%APACHE_NAME%/keystone.log
CustomLog /var/log/%APACHE_NAME%/access.log combined
</VirtualHost>
@@ -15,6 +16,7 @@
WSGIProcessGroup keystone-admin
WSGIScriptAlias / %ADMINWSGI%
WSGIApplicationGroup %{GLOBAL}
+ %ERRORLOGFORMAT%
ErrorLog /var/log/%APACHE_NAME%/keystone.log
CustomLog /var/log/%APACHE_NAME%/access.log combined
</VirtualHost>
diff --git a/lib/apache b/lib/apache
index f4f82a1..6d22290 100644
--- a/lib/apache
+++ b/lib/apache
@@ -61,6 +61,28 @@
fi
}
+# get_apache_version() - return the version of Apache installed
+# This function is used to determine the Apache version installed. There are
+# various differences between Apache 2.2 and 2.4 that warrant special handling.
+function get_apache_version {
+ if is_ubuntu; then
+ local version_str=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
+ elif is_fedora; then
+ local version_str=$(rpm -qa --queryformat '%{VERSION}' httpd)
+ elif is_suse; then
+ local version_str=$(rpm -qa --queryformat '%{VERSION}' apache2)
+ else
+ exit_distro_not_supported "cannot determine apache version"
+ fi
+ if [[ "$version_str" =~ ^2\.2\. ]]; then
+ echo "2.2"
+ elif [[ "$version_str" =~ ^2\.4\. ]]; then
+ echo "2.4"
+ else
+ exit_distro_not_supported "apache version not supported"
+ fi
+}
+
# apache_site_config_for() - The filename of the site's configuration file.
# This function uses the global variables APACHE_NAME and APACHE_CONF_DIR.
#
@@ -87,8 +109,8 @@
function apache_site_config_for {
local site=$@
if is_ubuntu; then
- local apache_version=$(sudo /usr/sbin/apache2ctl -v | awk '/Server version/ {print $3}' | cut -f2 -d/)
- if [[ "$apache_version" =~ ^2\.2\. ]]; then
+ local apache_version=$(get_apache_version)
+ if [[ "$apache_version" == "2.2" ]]; then
# Ubuntu 12.04 - Apache 2.2
echo $APACHE_CONF_DIR/${site}
else
diff --git a/lib/keystone b/lib/keystone
index c6e17ca..42acd50 100644
--- a/lib/keystone
+++ b/lib/keystone
@@ -123,6 +123,13 @@
sudo mkdir -p $KEYSTONE_WSGI_DIR
local keystone_apache_conf=$(apache_site_config_for keystone)
+ local apache_version=$(get_apache_version)
+
+ if [[ ${apache_version#*\.} -ge 4 ]]; then
+ # Apache 2.4 supports custom error log formats
+ # this should mirror the original log formatting.
+ local errorlogformat='ErrorLogFormat "%{cu}t %M"'
+ fi
# copy proxy vhost and wsgi file
sudo cp $KEYSTONE_DIR/httpd/keystone.py $KEYSTONE_WSGI_DIR/main
@@ -136,6 +143,7 @@
s|%PUBLICWSGI%|$KEYSTONE_WSGI_DIR/main|g;
s|%ADMINWSGI%|$KEYSTONE_WSGI_DIR/admin|g;
s|%USER%|$STACK_USER|g
+ s|%ERRORLOGFORMAT%|$errorlogformat|g;
" -i $keystone_apache_conf
enable_apache_site keystone
}