Fix custom log format
This commit is contained in:
parent
de8b9b8df2
commit
f0c758eed2
2 changed files with 12 additions and 8 deletions
|
@ -47,7 +47,7 @@ const (
|
||||||
|
|
||||||
gzipTypes = "application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"
|
gzipTypes = "application/atom+xml application/javascript application/x-javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component"
|
||||||
|
|
||||||
logFormatUpstream = `[$proxy_add_x_forwarded_for] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status"`
|
logFormatUpstream = `%v - [$proxy_add_x_forwarded_for] - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent" $request_length $request_time [$proxy_upstream_name] $upstream_addr $upstream_response_length $upstream_response_time $upstream_status"`
|
||||||
|
|
||||||
logFormatStream = `[$time_local] $protocol [$ssl_preread_server_name] [$stream_upstream] $status $bytes_sent $bytes_received $session_time`
|
logFormatStream = `[$time_local] $protocol [$ssl_preread_server_name] [$stream_upstream] $status $bytes_sent $bytes_received $session_time`
|
||||||
|
|
||||||
|
@ -305,10 +305,14 @@ func NewDefault() Configuration {
|
||||||
// proxy_protocol_addr as remote client address if UseProxyProtocol
|
// proxy_protocol_addr as remote client address if UseProxyProtocol
|
||||||
// is enabled.
|
// is enabled.
|
||||||
func (cfg Configuration) BuildLogFormatUpstream() string {
|
func (cfg Configuration) BuildLogFormatUpstream() string {
|
||||||
|
if cfg.LogFormatUpstream == logFormatUpstream {
|
||||||
if cfg.UseProxyProtocol {
|
if cfg.UseProxyProtocol {
|
||||||
return fmt.Sprintf("$proxy_protocol_addr - %s", cfg.LogFormatUpstream)
|
return fmt.Sprintf(cfg.LogFormatUpstream, "$proxy_protocol_addr")
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("$remote_addr - %s", cfg.LogFormatUpstream)
|
return fmt.Sprintf(cfg.LogFormatUpstream, "$remote_addr")
|
||||||
|
}
|
||||||
|
|
||||||
|
return cfg.LogFormatUpstream
|
||||||
}
|
}
|
||||||
|
|
||||||
// TemplateConfig contains the nginx configuration to render the file nginx.conf
|
// TemplateConfig contains the nginx configuration to render the file nginx.conf
|
||||||
|
|
|
@ -12,10 +12,10 @@ func TestBuildLogFormatUpstream(t *testing.T) {
|
||||||
curLogFormat string
|
curLogFormat string
|
||||||
expected string
|
expected string
|
||||||
}{
|
}{
|
||||||
{true, logFormatUpstream, fmt.Sprintf("$proxy_protocol_addr - %s", logFormatUpstream)},
|
{true, logFormatUpstream, fmt.Sprintf(logFormatUpstream, "$proxy_protocol_addr")},
|
||||||
{false, logFormatUpstream, fmt.Sprintf("$remote_addr - %s", logFormatUpstream)},
|
{false, logFormatUpstream, fmt.Sprintf(logFormatUpstream, "$remote_addr")},
|
||||||
{true, "my-log-format", "$proxy_protocol_addr - my-log-format"},
|
{true, "my-log-format", "my-log-format"},
|
||||||
{false, "john-log-format", "$remote_addr - john-log-format"},
|
{false, "john-log-format", "john-log-format"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
|
|
Loading…
Reference in a new issue