Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #427 from joelhandwell/loglevel
Add option to configure custom log level
  • Loading branch information
svanzoest committed Nov 6, 2016
2 parents 82e67ce + bff3a95 commit 5e5f886
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -176,6 +176,7 @@ values are noted.
* `node['apache']['keepaliverequests']` - Value for MaxKeepAliveRequests. Default is 100.
* `node['apache']['keepalivetimeout']` - Value for the KeepAliveTimeout directive. Default is 5.
* `node['apache']['sysconfig_additional_params']` - Additionals variables set in sysconfig file. Default is empty.
* `node['apache']['log_level']` - Value for LogLevel directive. Default is 'warn'.
* `node['apache']['default_modules']` - Array of module names. Can take "mod_FOO" or "FOO" as names, where FOO is the apache module, e.g. "`mod_status`" or "`status`".
* `node['apache']['mpm']` - With apache.version 2.4, specifies what Multi-Processing Module to enable. Defaults to platform default, otherwise it is "prefork"

Expand Down
1 change: 1 addition & 0 deletions attributes/default.rb
Expand Up @@ -288,6 +288,7 @@
default['apache']['default_site_port'] = '80'
default['apache']['access_file_name'] = '.htaccess'
default['apache']['default_release'] = nil
default['apache']['log_level'] = 'warn'

# Security
default['apache']['servertokens'] = 'Prod'
Expand Down
22 changes: 22 additions & 0 deletions spec/default_spec.rb
Expand Up @@ -99,6 +99,7 @@
)
expect(chef_run).to render_file(property[:apache][:conf]).with_content(/AccessFileName[\s]*\.htaccess/)
expect(chef_run).to render_file(property[:apache][:conf]).with_content(/Files ~ \"\^\\\.ht\"/)
expect(chef_run).to render_file(property[:apache][:conf]).with_content(/LogLevel warn/)
end

subject(:apacheconf) { chef_run.template(property[:apache][:conf]) }
Expand Down Expand Up @@ -296,6 +297,27 @@
end
end

context 'with custom LogLevel' do
before(:context) do
@chef_run = ChefSpec::SoloRunner.new(:platform => platform, :version => version) do |node|
node.set['apache']['log_level'] = 'error'
end

stub_command("#{property[:apache][:binary]} -t").and_return(false)
@chef_run.converge(described_recipe)
end

it "creates #{property[:apache][:conf]}" do
expect(chef_run).to create_template(property[:apache][:conf]).with(
:source => 'apache2.conf.erb',
:owner => 'root',
:group => property[:apache][:root_group],
:mode => '0644'
)
expect(chef_run).to render_file(property[:apache][:conf]).with_content(/LogLevel error/)
end
end

context 'with invalid apache configuration' do
before(:context) do
@chef_run = ChefSpec::SoloRunner.new(:platform => platform, :version => version)
Expand Down
2 changes: 1 addition & 1 deletion templates/default/apache2.conf.erb
Expand Up @@ -147,7 +147,7 @@ ErrorLog <%= node['apache']['log_dir'] %>/<%= node['apache']['error_log'] %>
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn
LogLevel <%= node['apache']['log_level'] %>

# COOK-1021: Dummy LoadModule directive to aid module installations
#LoadModule dummy_module modules/mod_dummy.so
Expand Down
2 changes: 1 addition & 1 deletion templates/default/default-site.conf.erb
Expand Up @@ -40,7 +40,7 @@ NameVirtualHost *:<%= node['apache']['default_site_port'] %>

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
LogLevel <%= node['apache']['log_level'] %>

CustomLog <%= node['apache']['log_dir'] %>/<%= node['apache']['access_log'] %> combined
ServerSignature On
Expand Down
Expand Up @@ -113,6 +113,7 @@
expect(config).to contain %Q(ServerRoot "#{property[:apache][:dir]}")
expect(config).to contain 'AccessFileName .htaccess'
expect(config).to contain 'Files ~ "^\.ht"'
expect(config).to contain 'LogLevel warn'
if property[:apache][:version] == '2.4'
expect(config).to contain "IncludeOptional #{property[:apache][:dir]}/conf-enabled/*.conf"
expect(config).to_not contain "Include #{property[:apache][:dir]}/conf.d/*.conf"
Expand Down

0 comments on commit 5e5f886

Please sign in to comment.