Skip to content

Commit

Permalink
Allow to set log_format's "escape" parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Aug 19, 2022
1 parent 6d59c0e commit 530337d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
Enum['on', 'off'] $http_tcp_nopush = 'off',
$keepalive_timeout = '65s',
$keepalive_requests = '100',
$log_format = {},
Hash[String[1], Nginx::LogFormat] $log_format = {},
Boolean $mail = false,
Variant[String, Boolean] $mime_types_path = 'mime.types',
Boolean $stream = false,
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@
' log_format format1 \'FORMAT1\';',
' log_format format2 \'FORMAT2\';',
' log_format format3 \'FORMAT3\';',
' log_format format4 \'escape=json\' \'{"response": $status, "verb": "$request_method"}\';'
' log_format format4 escape=json \'{"response": $status, "verb": "$request_method"}\';'
]
},
{
Expand Down
6 changes: 5 additions & 1 deletion templates/conf.d/nginx.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ http {
default_type application/octet-stream;
<% if @log_format -%>
<% @log_format.sort_by{|k,v| k}.each do |key,value| -%>
log_format <%= key %> '<%= value %>';
<%- if value.is_a?(String) -%>
log_format <%= key %> <%= Puppet::Pops::Types::StringConverter.convert(value, '%p') %>;
<%- else -%>
log_format <%= key %> <%= "escape=#{value['escape']} " if value['escape'] %><%= Puppet::Pops::Types::StringConverter.convert(value['format'], '%p') %>;
<%- end -%>
<% end -%>
<% end -%>
Expand Down
7 changes: 7 additions & 0 deletions types/logformat.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Nginx::LogFormat = Variant[
String[1],
Struct[{
Optional[escape] => Enum['default', 'json', 'none'],
format => String[1],
}],
]

0 comments on commit 530337d

Please sign in to comment.