From 2e221a7e0f685ae42dfddde635e0ad6320f9d62a Mon Sep 17 00:00:00 2001 From: "Joshua B. Bussdieker" Date: Sat, 2 Aug 2014 00:04:43 -0700 Subject: [PATCH 1/2] Support specifying log formats --- manifests/config.pp | 1 + manifests/init.pp | 3 +++ spec/classes/config_spec.rb | 12 ++++++++++++ templates/conf.d/nginx.conf.erb | 5 +++++ 4 files changed, 21 insertions(+) diff --git a/manifests/config.pp b/manifests/config.pp index 88b9b07..551921c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -57,6 +57,7 @@ class nginx::config( $http_tcp_nodelay = 'on', $http_tcp_nopush = 'off', $keepalive_timeout = '65', + $log_format = {}, $mail = false, $multi_accept = 'off', $names_hash_bucket_size = '64', diff --git a/manifests/init.pp b/manifests/init.pp index d184e16..998855d 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -79,6 +79,7 @@ class nginx ( $global_group = undef, $global_mode = undef, $logdir = undef, + $log_format = undef, $http_access_log = undef, $nginx_error_log = undef, $pid = undef, @@ -158,6 +159,7 @@ class nginx ( $http_tcp_nopush or $keepalive_timeout or $logdir or + $log_format or $mail or $multi_accept or $names_hash_bucket_size or @@ -237,6 +239,7 @@ class nginx ( http_tcp_nopush => $http_tcp_nopush, keepalive_timeout => $keepalive_timeout, log_dir => $logdir, + log_format => $log_format, mail => $mail, multi_accept => $multi_accept, names_hash_bucket_size => $names_hash_bucket_size, diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index 7222a25..caa070e 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -177,6 +177,18 @@ describe 'nginx::config' do :value => '100', :match => ' worker_connections 100;', }, + { + :title => 'should set log formats', + :attr => 'log_format', + :value => { + 'format1' => 'FORMAT1', + 'format2' => 'FORMAT2', + }, + :match => [ + ' log_format format1 \'FORMAT1\';', + ' log_format format2 \'FORMAT2\';', + ], + }, { :title => 'should set access_log', :attr => 'http_access_log', diff --git a/templates/conf.d/nginx.conf.erb b/templates/conf.d/nginx.conf.erb index 0fc5307..1582b0e 100644 --- a/templates/conf.d/nginx.conf.erb +++ b/templates/conf.d/nginx.conf.erb @@ -24,6 +24,11 @@ events { http { include <%= @conf_dir %>/mime.types; default_type application/octet-stream; +<% if @log_format -%> +<% @log_format.sort_by{|k,v| k}.each do |key,value| -%> + log_format <%= key %> '<%= value %>'; +<% end -%> +<% end -%> access_log <%= @http_access_log %>; From 9647d1278fc97ba7c842492634a4fe2edd938f94 Mon Sep 17 00:00:00 2001 From: Matthew Haughton Date: Wed, 3 Dec 2014 23:26:00 -0500 Subject: [PATCH 2/2] add negative test for log_format --- spec/classes/config_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb index caa070e..a79a444 100644 --- a/spec/classes/config_spec.rb +++ b/spec/classes/config_spec.rb @@ -189,6 +189,12 @@ describe 'nginx::config' do ' log_format format2 \'FORMAT2\';', ], }, + { + :title => 'should not set log formats', + :attr => 'log_format', + :value => {}, + :notmatch => /log_format/, + }, { :title => 'should set access_log', :attr => 'http_access_log',