Skip to content

Commit 421adf5

Browse files
author
Morgan Haskel
committed
Merge pull request #1096 from igalic/log_reject
Do not offload overriding LogFormats to httpd
2 parents 1962d73 + 91d23fd commit 421adf5

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ Specifies the location where apache module files are stored. It should not be co
357357

358358
#####`loadfile_name`
359359

360-
Sets the file name for the module loadfile. Should be in the format *.load. This can be used to set the module load order.
360+
Sets the file name for the module loadfile. Should be in the format \*.load. This can be used to set the module load order.
361361

362362
#####`log_level`
363363

@@ -371,6 +371,17 @@ Define additional [LogFormats](https://httpd.apache.org/docs/current/mod/mod_log
371371
$log_formats = { vhost_common => '%v %h %l %u %t \"%r\" %>s %b' }
372372
```
373373

374+
There are a number of predefined LogFormats in the httpd.conf that Puppet writes out:
375+
376+
```httpd
377+
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
378+
LogFormat "%h %l %u %t \"%r\" %>s %b" common
379+
LogFormat "%{Referer}i -> %U" referer
380+
LogFormat "%{User-agent}i" agent
381+
```
382+
383+
If your `$log_formats` contains one of those, they will be overwritten with **your** definition.
384+
374385
#####`logroot`
375386

376387
Changes the directory where Apache log files for the virtual host are placed. Defaults to '/var/log/httpd' on RedHat, '/var/log/apache2' on Debian, '/var/log/apache22' on FreeBSD, and '/var/log/apache2' on Gentoo.

spec/classes/apache_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,23 @@
218218
end
219219
end
220220

221+
describe "Override existing LogFormats" do
222+
context "When parameter log_formats is a hash" do
223+
let :params do
224+
{ :log_formats => {
225+
'common' => "%v %h %l %u %t \"%r\" %>s %b",
226+
'combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
227+
} }
228+
end
229+
230+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
231+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
232+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n} }
233+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
234+
it { is_expected.to contain_file("/etc/apache2/apache2.conf").without_content %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n} }
235+
end
236+
end
237+
221238
context "on Ubuntu" do
222239
let :facts do
223240
super().merge({

templates/httpd.conf.erb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,18 @@ Include "<%= @mod_load_dir %>/*.conf"
6060
<% end -%>
6161
Include "<%= @ports_file %>"
6262

63+
<% unless @log_formats.has_key?('combined') -%>
6364
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
65+
<% end -%>
66+
<% unless @log_formats.has_key?('common') -%>
6467
LogFormat "%h %l %u %t \"%r\" %>s %b" common
68+
<% end -%>
69+
<% unless @log_formats.has_key?('referer') -%>
6570
LogFormat "%{Referer}i -> %U" referer
71+
<% end -%>
72+
<% unless @log_formats.has_key?('agent') -%>
6673
LogFormat "%{User-agent}i" agent
74+
<% end -%>
6775
<% if @log_formats and !@log_formats.empty? -%>
6876
<%- @log_formats.sort.each do |nickname,format| -%>
6977
LogFormat "<%= format -%>" <%= nickname %>

0 commit comments

Comments
 (0)