diff --git a/README.md b/README.md index edcef8770..de7368dab 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/attributes/default.rb b/attributes/default.rb index 220b970e1..dfdf6ebf5 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -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' diff --git a/spec/default_spec.rb b/spec/default_spec.rb index d3f8b26a3..0af6613c1 100644 --- a/spec/default_spec.rb +++ b/spec/default_spec.rb @@ -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]) } @@ -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) diff --git a/templates/default/apache2.conf.erb b/templates/default/apache2.conf.erb index 94579f31d..13d132db0 100644 --- a/templates/default/apache2.conf.erb +++ b/templates/default/apache2.conf.erb @@ -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 diff --git a/templates/default/default-site.conf.erb b/templates/default/default-site.conf.erb index 536030801..6d7ae797f 100644 --- a/templates/default/default-site.conf.erb +++ b/templates/default/default-site.conf.erb @@ -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 diff --git a/test/integration/default/serverspec/localhost/default_spec.rb b/test/integration/default/serverspec/localhost/default_spec.rb index e0a12aa28..e6c83b2a9 100644 --- a/test/integration/default/serverspec/localhost/default_spec.rb +++ b/test/integration/default/serverspec/localhost/default_spec.rb @@ -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"