From c17b7db6ae8da641cd71d8207624eabe91111eae Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sun, 30 Sep 2018 23:48:16 +0200 Subject: [PATCH 1/2] Move error_log to the http context This aligns error_log and access_log --- spec/classes/nginx_spec.rb | 8 ++++---- templates/conf.d/nginx.conf.erb | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 24e0e3838..9778694e5 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -433,22 +433,22 @@ title: 'should set error_log', attr: 'nginx_error_log', value: '/path/to/error.log', - match: 'error_log /path/to/error.log error;' + match: ' error_log /path/to/error.log error;' }, { title: 'should set multiple error_logs', attr: 'nginx_error_log', value: ['/path/to/error.log', 'syslog:server=localhost'], match: [ - 'error_log /path/to/error.log error;', - 'error_log syslog:server=localhost error;' + ' error_log /path/to/error.log error;', + ' error_log syslog:server=localhost error;' ] }, { title: 'should set error_log severity level', attr: 'nginx_error_log_severity', value: 'warn', - match: 'error_log /var/log/nginx/error.log warn;' + match: ' error_log /var/log/nginx/error.log warn;' }, { title: 'should set pid', diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index a1c35e211..49e8a9344 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -20,13 +20,6 @@ worker_rlimit_nofile <%= @worker_rlimit_nofile %>; <% if @pid -%> pid <%= @pid %>; <% end -%> -<% if @nginx_error_log.is_a?(Array) -%> - <%- @nginx_error_log.each do |log_item| -%> -error_log <%= log_item %> <%= @nginx_error_log_severity %>; - <%- end -%> -<% else -%> -error_log <%= @nginx_error_log %> <%= @nginx_error_log_severity %>; -<% end -%> <% if @nginx_cfg_prepend -%> <%- field_width = @nginx_cfg_prepend.inject(0) { |l,(k,v)| k.size > l ? k.size : l } -%> @@ -84,6 +77,13 @@ http { <% else -%> access_log <%= @http_access_log %><% if @http_format_log %> <%= @http_format_log%><% end %>; <% end -%> +<% if @nginx_error_log.is_a?(Array) -%> + <%- @nginx_error_log.each do |log_item| -%> + error_log <%= log_item %> <%= @nginx_error_log_severity %>; + <%- end -%> +<% else -%> + error_log <%= @nginx_error_log %> <%= @nginx_error_log_severity %>; +<% end -%> <% if @sendfile == 'on' -%> sendfile on; From 32d2f7283e503bf4085b246fcb09e4ce5f676a87 Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Sun, 30 Sep 2018 23:49:40 +0200 Subject: [PATCH 2/2] Remove double spacing This double spacing doesn't align to anything so it doesn't make sense. --- spec/classes/nginx_spec.rb | 22 +++++++++++----------- templates/conf.d/nginx.conf.erb | 10 +++++----- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/spec/classes/nginx_spec.rb b/spec/classes/nginx_spec.rb index 9778694e5..747561b48 100644 --- a/spec/classes/nginx_spec.rb +++ b/spec/classes/nginx_spec.rb @@ -433,22 +433,22 @@ title: 'should set error_log', attr: 'nginx_error_log', value: '/path/to/error.log', - match: ' error_log /path/to/error.log error;' + match: ' error_log /path/to/error.log error;' }, { title: 'should set multiple error_logs', attr: 'nginx_error_log', value: ['/path/to/error.log', 'syslog:server=localhost'], match: [ - ' error_log /path/to/error.log error;', - ' error_log syslog:server=localhost error;' + ' error_log /path/to/error.log error;', + ' error_log syslog:server=localhost error;' ] }, { title: 'should set error_log severity level', attr: 'nginx_error_log_severity', value: 'warn', - match: ' error_log /var/log/nginx/error.log warn;' + match: ' error_log /var/log/nginx/error.log warn;' }, { title: 'should set pid', @@ -544,28 +544,28 @@ title: 'should set access_log', attr: 'http_access_log', value: '/path/to/access.log', - match: ' access_log /path/to/access.log;' + match: ' access_log /path/to/access.log;' }, { title: 'should set multiple access_logs', attr: 'http_access_log', value: ['/path/to/access.log', 'syslog:server=localhost'], match: [ - ' access_log /path/to/access.log;', - ' access_log syslog:server=localhost;' + ' access_log /path/to/access.log;', + ' access_log syslog:server=localhost;' ] }, { title: 'should set custom log format', attr: 'http_format_log', value: 'mycustomformat', - match: ' access_log /var/log/nginx/access.log mycustomformat;' + match: ' access_log /var/log/nginx/access.log mycustomformat;' }, { title: 'should set sendfile', attr: 'sendfile', value: 'on', - match: ' sendfile on;' + match: ' sendfile on;' }, { title: 'should not set sendfile', @@ -1183,12 +1183,12 @@ it { is_expected.to contain_file('/foo/bar').with(ensure: 'directory') } it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( - %r{access_log /foo/bar/access.log;} + %r{access_log /foo/bar/access.log;} ) end it do is_expected.to contain_file('/etc/nginx/nginx.conf').with_content( - %r{error_log /foo/bar/error.log error;} + %r{error_log /foo/bar/error.log error;} ) end end diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 49e8a9344..c2428c04f 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -72,21 +72,21 @@ http { <% end -%> <% if @http_access_log.is_a?(Array) -%> <%- @http_access_log.each do |log_item| -%> - access_log <%= log_item %><% if @http_format_log %> <%= @http_format_log%><% end %>; + access_log <%= log_item %><% if @http_format_log %> <%= @http_format_log%><% end %>; <%- end -%> <% else -%> - access_log <%= @http_access_log %><% if @http_format_log %> <%= @http_format_log%><% end %>; + access_log <%= @http_access_log %><% if @http_format_log %> <%= @http_format_log%><% end %>; <% end -%> <% if @nginx_error_log.is_a?(Array) -%> <%- @nginx_error_log.each do |log_item| -%> - error_log <%= log_item %> <%= @nginx_error_log_severity %>; + error_log <%= log_item %> <%= @nginx_error_log_severity %>; <%- end -%> <% else -%> - error_log <%= @nginx_error_log %> <%= @nginx_error_log_severity %>; + error_log <%= @nginx_error_log %> <%= @nginx_error_log_severity %>; <% end -%> <% if @sendfile == 'on' -%> - sendfile on; + sendfile on; <%- if @http_tcp_nopush == 'on' -%> tcp_nopush on; <%- end -%>