Skip to content

Commit

Permalink
Merge pull request #66 from domainfactory/log-format
Browse files Browse the repository at this point in the history
Support for custom log-format
  • Loading branch information
pleshakov authored Nov 15, 2016
2 parents 174ce61 + bdc4824 commit a73120c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
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

0 comments on commit a73120c

Please sign in to comment.