Skip to content

Commit ecb9515

Browse files
authored
Merge pull request #836 from coryfklein/master
Make log format json escaping configurable
2 parents 816b7f5 + fa70e5e commit ecb9515

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

controllers/nginx/pkg/config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ type Configuration struct {
175175
// Default: 4 8k
176176
LargeClientHeaderBuffers string `json:"large-client-header-buffers"`
177177

178+
// Enable json escaping
179+
// http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
180+
LogFormatEscapeJson bool `json:"log-format-escape-json,omitempty"`
181+
178182
// Customize upstream log_format
179183
// http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format
180184
LogFormatUpstream string `json:"log-format-upstream,omitempty"`
@@ -311,6 +315,7 @@ func NewDefault() Configuration {
311315
KeepAlive: 75,
312316
KeepAliveRequests: 100,
313317
LargeClientHeaderBuffers: "4 8k",
318+
LogFormatEscapeJson: false,
314319
LogFormatStream: logFormatStream,
315320
LogFormatUpstream: logFormatUpstream,
316321
MaxWorkerConnections: 16384,

controllers/nginx/rootfs/etc/nginx/template/nginx.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ http {
9393
# disable warnings
9494
uninitialized_variable_warn off;
9595

96-
log_format upstreaminfo '{{ buildLogFormatUpstream $cfg }}';
96+
log_format upstreaminfo {{ if $cfg.LogFormatEscapeJson }}escape=json {{ end }}'{{ buildLogFormatUpstream $cfg }}';
9797

9898
{{/* map urls that should not appear in access.log */}}
9999
{{/* http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log */}}

0 commit comments

Comments
 (0)