Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom log-format #66

Merged
merged 1 commit into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ func (lbc *LoadBalancerController) syncCfgm(key string) {
glog.Errorf("In configmap %v/%v 'http2' contains invalid declaration: %v, ignoring", cfgm.Namespace, cfgm.Name, err)
}
}
if logFormat, exists := cfgm.Data["log-format"]; exists {
cfg.MainLogFormat = logFormat
}
}
lbc.cnf.UpdateConfig(cfg)

Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Config struct {
HTTP2 bool
MainServerNamesHashBucketSize string
MainServerNamesHashMaxSize string
MainLogFormat string
}

// NewDefaultConfig creates a Config with default values
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ func (cnf *Configurator) UpdateConfig(config *Config) {
mainCfg := &NginxMainConfig{
ServerNamesHashBucketSize: config.MainServerNamesHashBucketSize,
ServerNamesHashMaxSize: config.MainServerNamesHashMaxSize,
LogFormat: config.MainLogFormat,
}

cnf.nginx.UpdateMainConfigFile(mainCfg)
Expand Down
5 changes: 4 additions & 1 deletion nginx-controller/nginx/nginx.conf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

{{if .LogFormat -}}
log_format main '{{.LogFormat}}';
{{- else -}}
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

{{- end }}
access_log /var/log/nginx/access.log main;

sendfile on;
Expand Down
3 changes: 2 additions & 1 deletion nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package nginx
import (
"bytes"
"fmt"
"html/template"
"text/template"
"os"
"os/exec"
"path"
Expand Down Expand Up @@ -62,6 +62,7 @@ type Location struct {
type NginxMainConfig struct {
ServerNamesHashBucketSize string
ServerNamesHashMaxSize string
LogFormat string
}

// NewUpstreamWithDefaultServer creates an upstream with the default server.
Expand Down