Skip to content

Commit ec10bad

Browse files
authored
Merge pull request #1452 from TuningYourCode/unify-access-log-settings
Unify (http_)log_format in nginx class and server resource
2 parents d51a170 + ff96616 commit ec10bad

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

manifests/init.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
String[1] $log_group = $nginx::params::log_group,
5454
Stdlib::Filemode $log_mode = $nginx::params::log_mode,
5555
Variant[String, Array[String]] $http_access_log = "${log_dir}/${nginx::params::http_access_log_file}",
56-
$http_format_log = undef,
56+
Optional[String] $http_format_log = undef,
5757
Variant[String, Array[String]] $nginx_error_log = "${log_dir}/${nginx::params::nginx_error_log_file}",
5858
Nginx::ErrorLogSeverity $nginx_error_log_severity = 'error',
5959
$pid = $nginx::params::pid,

manifests/resource/server.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
Optional[Array[String]] $include_files = undef,
391391
Optional[Variant[String, Array]] $access_log = undef,
392392
Optional[Variant[String, Array]] $error_log = undef,
393-
$format_log = 'combined',
393+
Optional[String] $format_log = $nginx::http_format_log,
394394
Optional[Hash] $passenger_cgi_param = undef,
395395
Optional[Hash] $passenger_set_header = undef,
396396
Optional[Hash] $passenger_env_var = undef,

spec/defines/resource_server_spec.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
'group' => 'root',
3636
'mode' => '0644')
3737
end
38-
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{access_log\s+/var/log/nginx/www\.rspec\.example\.com\.access\.log combined;}) }
38+
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{access_log\s+/var/log/nginx/www\.rspec\.example\.com\.access\.log;}) }
3939
it { is_expected.to contain_concat__fragment("#{title}-header").with_content(%r{error_log\s+/var/log/nginx/www\.rspec\.example\.com\.error\.log}) }
4040
it { is_expected.to contain_concat__fragment("#{title}-footer") }
4141
it { is_expected.to contain_nginx__resource__location("#{title}-default") }
@@ -294,15 +294,15 @@
294294
title: 'should set access_log',
295295
attr: 'access_log',
296296
value: '/path/to/access.log',
297-
match: ' access_log /path/to/access.log combined;'
297+
match: ' access_log /path/to/access.log;'
298298
},
299299
{
300300
title: 'should set multiple access_log directives',
301301
attr: 'access_log',
302302
value: ['/path/to/log/1', 'syslog:server=localhost'],
303303
match: [
304-
' access_log /path/to/log/1 combined;',
305-
' access_log syslog:server=localhost combined;'
304+
' access_log /path/to/log/1;',
305+
' access_log syslog:server=localhost;'
306306
]
307307
},
308308
{
@@ -315,7 +315,7 @@
315315
title: 'should set access_log to syslog',
316316
attr: 'access_log',
317317
value: 'syslog:server=localhost',
318-
match: ' access_log syslog:server=localhost combined;'
318+
match: ' access_log syslog:server=localhost;'
319319
},
320320
{
321321
title: 'should set format_log custom_format',
@@ -905,15 +905,15 @@
905905
title: 'should set access_log',
906906
attr: 'access_log',
907907
value: '/path/to/access.log',
908-
match: ' access_log /path/to/access.log combined;'
908+
match: ' access_log /path/to/access.log;'
909909
},
910910
{
911911
title: 'should set multiple access_log directives',
912912
attr: 'access_log',
913913
value: ['/path/to/log/1', 'syslog:server=localhost'],
914914
match: [
915-
' access_log /path/to/log/1 combined;',
916-
' access_log syslog:server=localhost combined;'
915+
' access_log /path/to/log/1;',
916+
' access_log syslog:server=localhost;'
917917
]
918918
},
919919
{
@@ -932,7 +932,7 @@
932932
title: 'should set access_log to syslog',
933933
attr: 'access_log',
934934
value: 'syslog:server=localhost',
935-
match: ' access_log syslog:server=localhost combined;'
935+
match: ' access_log syslog:server=localhost;'
936936
},
937937
{
938938
title: 'should set format_log custom_format',
@@ -1418,7 +1418,7 @@
14181418
end
14191419

14201420
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
1421-
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log combined;}) }
1421+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log;}) }
14221422
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
14231423
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate\s+dummy.cert;}) }
14241424
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_certificate_key\s+dummy.key;}) }
@@ -1437,7 +1437,7 @@
14371437
end
14381438

14391439
it { is_expected.to contain_nginx__resource__location("#{title}-default").with_ssl_only(true) }
1440-
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log combined;}) }
1440+
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{access_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.access\.log;}) }
14411441
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{error_log\s+/var/log/nginx/ssl-www\.rspec\.example\.com\.error\.log}) }
14421442
it { is_expected.to contain_concat__fragment("#{title}-ssl-header").with_content(%r{ssl_verify_client\s+optional;}) }
14431443
end

templates/server/server_header.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ server {
163163
<% end -%>
164164
<% if @access_log.is_a?(Array) -%>
165165
<%- @access_log.each do |log_item| -%>
166-
access_log <%= log_item %> <%= @format_log %>;
166+
access_log <%= log_item %><% if @format_log %> <%= @format_log%><% end %>;
167167
<%- end -%>
168168
<% elsif @access_log == 'absent' -%>
169169
<% elsif @access_log == 'off' -%>
170170
access_log off;
171171
<% elsif not @access_log -%>
172-
access_log <%= scope['::nginx::config::log_dir'] %>/<%= @name_sanitized %>.access.log <%= @format_log %>;
172+
access_log <%= scope['::nginx::config::log_dir'] %>/<%= @name_sanitized %>.access.log<% if @format_log %> <%= @format_log%><% end %>;
173173
<% else -%>
174-
access_log <%= @access_log %> <%= @format_log %>;
174+
access_log <%= @access_log %><% if @format_log %> <%= @format_log%><% end %>;
175175
<% end -%>
176176
<% if @error_log.is_a?(Array) -%>
177177
<%- @error_log.each do |log_item| -%>

templates/server/server_ssl_header.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ server {
9696
<% end -%>
9797
<% if @access_log.is_a?(Array) -%>
9898
<%- @access_log.each do |log_item| -%>
99-
access_log <%= log_item %> <%= @format_log %>;
99+
access_log <%= log_item %><% if @format_log %> <%= @format_log%><% end %>;
100100
<%- end -%>
101101
<% elsif @access_log == 'absent' -%>
102102
<% elsif @access_log == 'off' -%>
103103
access_log off;
104104
<% elsif not @access_log -%>
105-
access_log <%= scope['::nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.access.log <%= @format_log %>;
105+
access_log <%= scope['::nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.access.log<% if @format_log %> <%= @format_log%><% end %>;
106106
<% else -%>
107-
access_log <%= @access_log %> <%= @format_log %>;
107+
access_log <%= @access_log %><% if @format_log %> <%= @format_log%><% end %>;
108108
<% end -%>
109109
<% if @error_log.is_a?(Array) -%>
110110
<%- @error_log.each do |log_item| -%>

0 commit comments

Comments
 (0)