Merge pull request #1243 from maxlaverse/custom_access_log_path

Add support for access-log-path and error-log-path
This commit is contained in:
Manuel Alejandro de Brito Fontes 2017-08-25 08:29:06 -04:00 committed by GitHub
commit 3499524282
4 changed files with 24 additions and 4 deletions

View file

@ -311,6 +311,10 @@ Example usage: `custom-http-errors: 404,415`
**disable-access-log:** Disables the Access Log from the entire Ingress Controller. This is 'false' by default. **disable-access-log:** Disables the Access Log from the entire Ingress Controller. This is 'false' by default.
**access-log-path:** Access log path. Goes to '/var/log/nginx/access.log' by default. http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
**error-log-path:** Error log path. Goes to '/var/log/nginx/error.log' by default. http://nginx.org/en/docs/ngx_core_module.html#error_log
**disable-ipv6:** Disable listening on IPV6. This is 'false' by default. **disable-ipv6:** Disable listening on IPV6. This is 'false' by default.
**enable-dynamic-tls-records:** Enables dynamically sized TLS records to improve time-to-first-byte. Enabled by default. See [CloudFlare's blog](https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency) for more information. **enable-dynamic-tls-records:** Enables dynamically sized TLS records to improve time-to-first-byte. Enabled by default. See [CloudFlare's blog](https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency) for more information.

View file

@ -92,6 +92,16 @@ type Configuration struct {
// By default this is disabled // By default this is disabled
AllowBackendServerHeader bool `json:"allow-backend-server-header"` AllowBackendServerHeader bool `json:"allow-backend-server-header"`
// AccessLogPath sets the path of the access logs if enabled
// http://nginx.org/en/docs/http/ngx_http_log_module.html#access_log
// By default access logs go to /var/log/nginx/access.log
AccessLogPath string `json:"access-log-path,omitempty"`
// ErrorLogPath sets the path of the error logs
// http://nginx.org/en/docs/ngx_core_module.html#error_log
// By default error logs go to /var/log/nginx/error.log
ErrorLogPath string `json:"error-log-path,omitempty"`
// EnableDynamicTLSRecords enables dynamic TLS record sizes // EnableDynamicTLSRecords enables dynamic TLS record sizes
// https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency // https://blog.cloudflare.com/optimizing-tls-over-tcp-to-reduce-latency
// By default this is enabled // By default this is enabled
@ -340,6 +350,8 @@ func NewDefault() Configuration {
defIPCIDR = append(defIPCIDR, "0.0.0.0/0") defIPCIDR = append(defIPCIDR, "0.0.0.0/0")
cfg := Configuration{ cfg := Configuration{
AllowBackendServerHeader: false, AllowBackendServerHeader: false,
AccessLogPath: "/var/log/nginx/access.log",
ErrorLogPath: "/var/log/nginx/error.log",
ClientHeaderBufferSize: "1k", ClientHeaderBufferSize: "1k",
ClientHeaderTimeout: 60, ClientHeaderTimeout: 60,
ClientBodyBufferSize: "8k", ClientBodyBufferSize: "8k",

View file

@ -39,6 +39,8 @@ func TestMergeConfigMapToStruct(t *testing.T) {
"skip-access-log-urls": "/log,/demo,/test", "skip-access-log-urls": "/log,/demo,/test",
"use-proxy-protocol": "true", "use-proxy-protocol": "true",
"disable-access-log": "true", "disable-access-log": "true",
"access-log-path": "/var/log/test/access.log",
"error-log-path": "/var/log/test/error.log",
"use-gzip": "true", "use-gzip": "true",
"enable-dynamic-tls-records": "false", "enable-dynamic-tls-records": "false",
"gzip-types": "text/html", "gzip-types": "text/html",
@ -47,6 +49,8 @@ func TestMergeConfigMapToStruct(t *testing.T) {
def := config.NewDefault() def := config.NewDefault()
def.CustomHTTPErrors = []int{300, 400} def.CustomHTTPErrors = []int{300, 400}
def.DisableAccessLog = true def.DisableAccessLog = true
def.AccessLogPath = "/var/log/test/access.log"
def.ErrorLogPath = "/var/log/test/error.log"
def.SkipAccessLogURLs = []string{"/log", "/demo", "/test"} def.SkipAccessLogURLs = []string{"/log", "/demo", "/test"}
def.ProxyReadTimeout = 1 def.ProxyReadTimeout = 1
def.ProxySendTimeout = 2 def.ProxySendTimeout = 2

View file

@ -118,9 +118,9 @@ http {
{{ if $cfg.DisableAccessLog }} {{ if $cfg.DisableAccessLog }}
access_log off; access_log off;
{{ else }} {{ else }}
access_log /var/log/nginx/access.log upstreaminfo if=$loggable; access_log {{ $cfg.AccessLogPath }} upstreaminfo if=$loggable;
{{ end }} {{ end }}
error_log /var/log/nginx/error.log {{ $cfg.ErrorLogLevel }}; error_log {{ $cfg.ErrorLogPath }} {{ $cfg.ErrorLogLevel }};
{{ buildResolvers $cfg.Resolver }} {{ buildResolvers $cfg.Resolver }}
@ -417,10 +417,10 @@ stream {
{{ if $cfg.DisableAccessLog }} {{ if $cfg.DisableAccessLog }}
access_log off; access_log off;
{{ else }} {{ else }}
access_log /var/log/nginx/access.log log_stream; access_log {{ $cfg.AccessLogPath }} log_stream;
{{ end }} {{ end }}
error_log /var/log/nginx/error.log; error_log {{ $cfg.ErrorLogPath }};
# TCP services # TCP services
{{ range $i, $tcpServer := .TCPBackends }} {{ range $i, $tcpServer := .TCPBackends }}