Skip to content

Commit

Permalink
Merge pull request #1513 from voxpupuli/log_format-escape-json
Browse files Browse the repository at this point in the history
  • Loading branch information
smortex committed Aug 24, 2022
2 parents 30b84c8 + c8273df commit 113f3d2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 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
15 changes: 12 additions & 3 deletions spec/classes/nginx_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -544,11 +544,20 @@
attr: 'log_format',
value: {
'format1' => 'FORMAT1',
'format2' => 'FORMAT2'
'format2' => 'FORMAT2',
'format3' => {
'format' => 'FORMAT3',
},
'format4' => {
'escape' => 'json',
'format' => '{"response": $status, "verb": "$request_method"}',
},
},
match: [
' log_format format1 \'FORMAT1\';',
' log_format format2 \'FORMAT2\';'
' 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 113f3d2

Please sign in to comment.