From 034015a8d7000084bf63bf12cc3410d714961289 Mon Sep 17 00:00:00 2001 From: Alexandre Fiori Date: Tue, 15 Mar 2016 09:36:02 -0400 Subject: [PATCH] Make log timestamps optional; new version On systemd we had duplicated timestamps so they're optional now. --- apiserver/config.go | 8 +++++++- apiserver/main.go | 6 ++++-- cmd/freegeoip/ansible-playbook/freegeoip.yml | 2 +- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apiserver/config.go b/apiserver/config.go index 6e1cf92..403399f 100644 --- a/apiserver/config.go +++ b/apiserver/config.go @@ -31,6 +31,7 @@ type Config struct { UseXForwardedFor bool Silent bool LogToStdout bool + LogTimestamp bool RedisAddr string RedisTimeout time.Duration MemcacheAddr string @@ -57,6 +58,7 @@ func NewConfig() *Config { DB: freegeoip.MaxMindDB, UpdateInterval: 24 * time.Hour, RetryInterval: 2 * time.Hour, + LogTimestamp: true, RedisAddr: "localhost:6379", RedisTimeout: time.Second, MemcacheAddr: "localhost:11211", @@ -83,6 +85,7 @@ func (c *Config) AddFlags(fs *flag.FlagSet) { fs.BoolVar(&c.UseXForwardedFor, "use-x-forwarded-for", c.UseXForwardedFor, "Use the X-Forwarded-For header when available (e.g. behind proxy)") fs.BoolVar(&c.Silent, "silent", c.Silent, "Disable HTTP and HTTPS log request details") fs.BoolVar(&c.LogToStdout, "logtostdout", c.LogToStdout, "Log to stdout instead of stderr") + fs.BoolVar(&c.LogTimestamp, "logtimestamp", c.LogTimestamp, "Prefix non-access logs with timestamp") fs.StringVar(&c.RedisAddr, "redis", c.RedisAddr, "Redis address in form of host:port[,host:port] for quota") fs.DurationVar(&c.RedisTimeout, "redis-timeout", c.RedisTimeout, "Redis read/write timeout") fs.StringVar(&c.MemcacheAddr, "memcache", c.MemcacheAddr, "Memcache address in form of host:port[,host:port] for quota") @@ -101,7 +104,10 @@ func (c *Config) logWriter() io.Writer { } func (c *Config) errorLogger() *log.Logger { - return log.New(c.logWriter(), "[error] ", log.LstdFlags) + if c.LogTimestamp { + return log.New(c.logWriter(), "[error] ", log.LstdFlags) + } + return log.New(c.logWriter(), "[error] ", 0) } func (c *Config) accessLogger() *log.Logger { diff --git a/apiserver/main.go b/apiserver/main.go index 179bc5c..2febb8e 100644 --- a/apiserver/main.go +++ b/apiserver/main.go @@ -19,7 +19,7 @@ import ( ) // Version tag. -var Version = "3.1.2" +var Version = "3.1.3" // Run is the entrypoint for the freegeoip server. func Run() { @@ -34,7 +34,9 @@ func Run() { if c.LogToStdout { log.SetOutput(os.Stdout) } - log.SetPrefix("[freegeoip] ") + if !c.LogTimestamp { + log.SetFlags(0) + } f, err := NewHandler(c) if err != nil { log.Fatal(err) diff --git a/cmd/freegeoip/ansible-playbook/freegeoip.yml b/cmd/freegeoip/ansible-playbook/freegeoip.yml index 3b71cb4..0f3ccfe 100644 --- a/cmd/freegeoip/ansible-playbook/freegeoip.yml +++ b/cmd/freegeoip/ansible-playbook/freegeoip.yml @@ -10,7 +10,7 @@ - redis vars: nodeexporter_url: http://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz - freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.2/freegeoip-3.1.2-linux-amd64.tar.gz + freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.3/freegeoip-3.1.3-linux-amd64.tar.gz freegeoip_params: - -http=:80 - -https=:443