From 280cc84af13d1aa8502949d2e22171cb78315972 Mon Sep 17 00:00:00 2001 From: aa07884 Date: Wed, 22 May 2024 10:29:33 +0200 Subject: [PATCH] Allow specifying error_log severity for servers fixes #1416 --- REFERENCE.md | 12 ++++++++++-- manifests/resource/server.pp | 6 ++++-- spec/defines/resource_server_spec.rb | 24 ++++++++++++++++++++++++ templates/server/server_header.erb | 12 ++++++------ templates/server/server_ssl_header.erb | 12 ++++++------ 5 files changed, 50 insertions(+), 16 deletions(-) diff --git a/REFERENCE.md b/REFERENCE.md index 2f66452f8..bcaa1c97d 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -3322,6 +3322,7 @@ The following parameters are available in the `nginx::resource::server` defined * [`include_files`](#-nginx--resource--server--include_files) * [`access_log`](#-nginx--resource--server--access_log) * [`error_log`](#-nginx--resource--server--error_log) +* [`error_log_severity`](#-nginx--resource--server--error_log_severity) * [`passenger_cgi_param`](#-nginx--resource--server--passenger_cgi_param) * [`passenger_set_header`](#-nginx--resource--server--passenger_set_header) * [`passenger_env_var`](#-nginx--resource--server--passenger_env_var) @@ -4177,12 +4178,19 @@ Default value: `undef` Data type: `Optional[Variant[String, Array]]` -Where to write error log. May add additional options like error level to -the end. May set to 'absent', in which case it will be omitted in this +Where to write error log. May be set to 'absent', in which case it will be omitted in this server stanza (and default to nginx.conf setting) Default value: `undef` +##### `error_log_severity` + +Data type: `Optional[Nginx::ErrorLogSeverity]` + +Optional error level + +Default value: `undef` + ##### `passenger_cgi_param` Data type: `Optional[Hash]` diff --git a/manifests/resource/server.pp b/manifests/resource/server.pp index 84961943b..0e77b9ceb 100644 --- a/manifests/resource/server.pp +++ b/manifests/resource/server.pp @@ -233,9 +233,10 @@ # server stanza, rather than setting a default. Can also be disabled for this # server with the string 'off'. # @param error_log -# Where to write error log. May add additional options like error level to -# the end. May set to 'absent', in which case it will be omitted in this +# Where to write error log. May be set to 'absent', in which case it will be omitted in this # server stanza (and default to nginx.conf setting) +# @param error_log_severity +# Optional error level # @param passenger_cgi_param # Allows one to define additional CGI environment variables to pass to the backend application # @param passenger_set_header @@ -399,6 +400,7 @@ Optional[Array[String]] $include_files = undef, Optional[Variant[String, Array]] $access_log = undef, Optional[Variant[String, Array]] $error_log = undef, + Optional[Nginx::ErrorLogSeverity] $error_log_severity = undef, Optional[String] $format_log = $nginx::http_format_log, Optional[Hash] $passenger_cgi_param = undef, Optional[Hash] $passenger_set_header = undef, diff --git a/spec/defines/resource_server_spec.rb b/spec/defines/resource_server_spec.rb index 212beb91e..8a221db56 100644 --- a/spec/defines/resource_server_spec.rb +++ b/spec/defines/resource_server_spec.rb @@ -358,6 +358,18 @@ ' error_log syslog:server=localhost;' ] }, + { + title: 'should set error_log severity level', + attr: 'error_log_severity', + value: 'warn', + match: ' error_log /var/log/nginx/www.rspec.example.com.error.log warn;' + }, + { + title: 'should not set error_log severity level', + attr: 'error_log_severity', + value: :undef, + match: ' error_log /var/log/nginx/www.rspec.example.com.error.log;' + }, { title: 'should not include error_log in server when set to absent', attr: 'error_log', @@ -1017,6 +1029,18 @@ ' error_log syslog:server=localhost;' ] }, + { + title: 'should set error_log severity level', + attr: 'error_log_severity', + value: 'warn', + match: ' error_log /var/log/nginx/ssl-www.rspec.example.com.error.log warn;' + }, + { + title: 'should not set error_log severity level', + attr: 'error_log_severity', + value: :undef, + match: ' error_log /var/log/nginx/ssl-www.rspec.example.com.error.log;' + }, { title: 'should not include error_log in server when set to absent', attr: 'error_log', diff --git a/templates/server/server_header.erb b/templates/server/server_header.erb index c641818ee..138c315c0 100644 --- a/templates/server/server_header.erb +++ b/templates/server/server_header.erb @@ -48,13 +48,13 @@ server { <% end -%> <% if @error_log.is_a?(Array) -%> <%- @error_log.each do |log_item| -%> - error_log <%= log_item %>; + error_log <%= log_item %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <%- end -%> <% elsif @error_log == 'absent' -%> <% elsif not @error_log -%> - error_log <%= scope['nginx::config::log_dir'] %>/<%= @name_sanitized %>.error.log; + error_log <%= scope['nginx::config::log_dir'] %>/<%= @name_sanitized %>.error.log<% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% else -%> - error_log <%= @error_log %>; + error_log <%= @error_log %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% end -%> } @@ -200,13 +200,13 @@ server { <% end -%> <% if @error_log.is_a?(Array) -%> <%- @error_log.each do |log_item| -%> - error_log <%= log_item %>; + error_log <%= log_item %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <%- end -%> <% elsif @error_log == 'absent' -%> <% elsif not @error_log -%> - error_log <%= scope['nginx::config::log_dir'] %>/<%= @name_sanitized %>.error.log; + error_log <%= scope['nginx::config::log_dir'] %>/<%= @name_sanitized %>.error.log<% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% else -%> - error_log <%= @error_log %>; + error_log <%= @error_log %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% end -%> <% if @error_pages -%> diff --git a/templates/server/server_ssl_header.erb b/templates/server/server_ssl_header.erb index 4f496943a..1bcee36f9 100644 --- a/templates/server/server_ssl_header.erb +++ b/templates/server/server_ssl_header.erb @@ -31,13 +31,13 @@ server { <% end -%> <% if @error_log.is_a?(Array) -%> <%- @error_log.each do |log_item| -%> - error_log <%= log_item %>; + error_log <%= log_item %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <%- end -%> <% elsif @error_log == 'absent' -%> <% elsif not @error_log -%> - error_log <%= scope['nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.error.log; + error_log <%= scope['nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.error.log<% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% else -%> - error_log <%= @error_log %>; + error_log <%= @error_log %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% end -%> <%= scope.function_template(["nginx/server/server_ssl_settings.erb"]) %> @@ -129,13 +129,13 @@ server { <% end -%> <% if @error_log.is_a?(Array) -%> <%- @error_log.each do |log_item| -%> - error_log <%= log_item %>; + error_log <%= log_item %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <%- end -%> <% elsif @error_log == 'absent' -%> <% elsif not @error_log -%> - error_log <%= scope['nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.error.log; + error_log <%= scope['nginx::config::log_dir'] %>/ssl-<%= @name_sanitized %>.error.log<% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% else -%> - error_log <%= @error_log %>; + error_log <%= @error_log %><% if @error_log_severity %> <%= @error_log_severity %><% end %>; <% end -%> <% if @error_pages -%>