Add ability to configure the apache logs
This change supports a new entry in the model to tune the configuration
of the error and custom logs. If absent, it defaults to the same
settings as before.
diff --git a/README.rst b/README.rst
index 0780397..0afea1a 100644
--- a/README.rst
+++ b/README.rst
@@ -150,6 +150,28 @@
# Set X-Frame-Options
frame_options: sameorigin
+Tune the log configuration:
+
+.. code-block:: yaml
+
+ parameters:
+ apache:
+ server:
+ site:
+ foo:
+ enabled: true
+ type: static
+ log:
+ custom:
+ enabled: true
+ file: /var/log/apache2/mylittleponysitecustom.log
+ format: >-
+ %{X-Forwarded-For}i %l %u %t \"%r\" %>s %b %D \"%{Referer}i\" \"%{User-Agent}i\"
+ error:
+ enabled: false
+ file: /var/log/apache2/foo.error.log
+ level: notice
+
Example pillar
==============
diff --git a/apache/files/_log.conf b/apache/files/_log.conf
index 1fab463..851d60c 100644
--- a/apache/files/_log.conf
+++ b/apache/files/_log.conf
@@ -1,5 +1,11 @@
+{%- from "apache/map.jinja" import server with context %}
+{%- set error_log = site.get('log', {}).get('error', {}) %}
+{%- set custom_log = site.get('log', {}).get('custom', {}) %}
- LogLevel warn
-
- ErrorLog /var/log/apache2/{{ site_name }}.error.log
- CustomLog /var/log/apache2/{{ site_name }}.access.log vhost_combined
+{%- if error_log.get('enabled', True) %}
+ LogLevel {{ error_log.level|default('warn') }}
+ ErrorLog {{ error_log.file|default(server.log_dir ~ '/' ~ site_name ~ '.error.log') }}
+{%- endif %}
+{%- if custom_log.get('enabled', True) %}
+ CustomLog {{ custom_log.file|default(server.log_dir ~ '/' ~ site_name ~ '.access.log') }} "{{ custom_log.format|default('vhost_combined') }}"
+{%- endif %}