Skip to content

Commit

Permalink
Merge pull request #682 from igalic/logformat
Browse files Browse the repository at this point in the history
A first stab at extending LogFormats
  • Loading branch information
Ashley Penney committed Mar 27, 2014
2 parents 94dc546 + af13807 commit cbcefb1
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,14 @@ Sets the amount of time the server will wait for subsequent requests on a persis

Changes the verbosity level of the error log. Defaults to 'warn'. Valid values are 'emerg', 'alert', 'crit', 'error', 'warn', 'notice', 'info', or 'debug'.

#####`log_formats`

Define additional [LogFormats](https://httpd.apache.org/docs/current/mod/mod_log_config.html#logformat). This is done in a Hash:

```puppet
$log_formats = { vhost_common => '%v %h %l %u %t \"%r\" %>s %b' }
```

#####`logroot`

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, and '/var/log/apache22' on FreeBSD.
Expand Down
1 change: 1 addition & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$keepalive_timeout = $::apache::params::keepalive_timeout,
$logroot = $::apache::params::logroot,
$log_level = $::apache::params::log_level,
$log_formats = {},
$ports_file = $::apache::params::ports_file,
$apache_version = $::apache::version::default,
$server_tokens = 'OS',
Expand Down
23 changes: 23 additions & 0 deletions spec/acceptance/apache_parameters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,29 @@ class { 'apache':
end
end

describe 'logformats' do
describe 'setup' do
it 'applies cleanly' do
pp = <<-EOS
class { 'apache':
{ log_formats => {
'vhost_common' => '%v %h %l %u %t \"%r\" %>s %b',
'vhost_combined' => '%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"',
}
}
EOS
apply_manifest(pp, :catch_failures => true)
end
end

describe file($conf_file) do
it { should be_file }
it { should contain 'LogFormat %v %h %l %u %t \"%r\" %>s %b" vhost_common' }
it { should contain 'LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined' }
end
end


describe 'keepalive' do
describe 'setup' do
it 'applies cleanly' do
Expand Down
14 changes: 14 additions & 0 deletions spec/classes/apache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@
end
end

describe "Add extra LogFormats" do
context "When parameter log_formats is a hash" do
let :params do
{ :log_formats => {
'vhost_common' => "%v %h %l %u %t \"%r\" %>s %b",
'vhost_combined' => "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\""
} }
end

it { should contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common\n} }
it { should contain_file("/etc/apache2/apache2.conf").with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" vhost_combined\n} }
end
end

context "on Ubuntu" do
let :facts do
super().merge({
Expand Down
5 changes: 5 additions & 0 deletions templates/httpd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combine
LogFormat "%h %l %u %t \"%r\" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent
<% if @log_formats and !@log_formats.empty? -%>
<%- @log_formats.each do |nickname,format| -%>
LogFormat "<%= format -%>" <%= nickname %>
<%- end -%>
<% end -%>

<%- if @apache_version >= '2.4' -%>
IncludeOptional "<%= @confd_dir %>/*.conf"
Expand Down

0 comments on commit cbcefb1

Please sign in to comment.