Skip to content

Commit

Permalink
Allow to set log_format's "escape" parameter
Browse files Browse the repository at this point in the history
While here, rely on #inspect to generate espaped quoted string.
  • Loading branch information
smortex committed Aug 24, 2022
1 parent 6d59c0e commit c8273df
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 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
8 changes: 4 additions & 4 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -554,10 +554,10 @@
},
},
match: [
' log_format format1 \'FORMAT1\';',
' log_format format2 \'FORMAT2\';',
' log_format format3 \'FORMAT3\';',
' log_format format4 \'escape=json\' \'{"response": $status, "verb": "$request_method"}\';'
' log_format format1 "FORMAT1";',
' log_format format2 "FORMAT2";',
' log_format format3 "FORMAT3";',
' 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?(Hash) -%>
log_format <%= key %> <%= "escape=#{value['escape']} " if value['escape'] %><%= value['format'].inspect %>;
<%- else -%>
log_format <%= key %> <%= value.inspect %>;
<%- 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 c8273df

Please sign in to comment.