Skip to content

Commit 034015a

Browse files
committed
Make log timestamps optional; new version
On systemd we had duplicated timestamps so they're optional now.
1 parent 7969483 commit 034015a

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

apiserver/config.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type Config struct {
3131
UseXForwardedFor bool
3232
Silent bool
3333
LogToStdout bool
34+
LogTimestamp bool
3435
RedisAddr string
3536
RedisTimeout time.Duration
3637
MemcacheAddr string
@@ -57,6 +58,7 @@ func NewConfig() *Config {
5758
DB: freegeoip.MaxMindDB,
5859
UpdateInterval: 24 * time.Hour,
5960
RetryInterval: 2 * time.Hour,
61+
LogTimestamp: true,
6062
RedisAddr: "localhost:6379",
6163
RedisTimeout: time.Second,
6264
MemcacheAddr: "localhost:11211",
@@ -83,6 +85,7 @@ func (c *Config) AddFlags(fs *flag.FlagSet) {
8385
fs.BoolVar(&c.UseXForwardedFor, "use-x-forwarded-for", c.UseXForwardedFor, "Use the X-Forwarded-For header when available (e.g. behind proxy)")
8486
fs.BoolVar(&c.Silent, "silent", c.Silent, "Disable HTTP and HTTPS log request details")
8587
fs.BoolVar(&c.LogToStdout, "logtostdout", c.LogToStdout, "Log to stdout instead of stderr")
88+
fs.BoolVar(&c.LogTimestamp, "logtimestamp", c.LogTimestamp, "Prefix non-access logs with timestamp")
8689
fs.StringVar(&c.RedisAddr, "redis", c.RedisAddr, "Redis address in form of host:port[,host:port] for quota")
8790
fs.DurationVar(&c.RedisTimeout, "redis-timeout", c.RedisTimeout, "Redis read/write timeout")
8891
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 {
101104
}
102105

103106
func (c *Config) errorLogger() *log.Logger {
104-
return log.New(c.logWriter(), "[error] ", log.LstdFlags)
107+
if c.LogTimestamp {
108+
return log.New(c.logWriter(), "[error] ", log.LstdFlags)
109+
}
110+
return log.New(c.logWriter(), "[error] ", 0)
105111
}
106112

107113
func (c *Config) accessLogger() *log.Logger {

apiserver/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// Version tag.
22-
var Version = "3.1.2"
22+
var Version = "3.1.3"
2323

2424
// Run is the entrypoint for the freegeoip server.
2525
func Run() {
@@ -34,7 +34,9 @@ func Run() {
3434
if c.LogToStdout {
3535
log.SetOutput(os.Stdout)
3636
}
37-
log.SetPrefix("[freegeoip] ")
37+
if !c.LogTimestamp {
38+
log.SetFlags(0)
39+
}
3840
f, err := NewHandler(c)
3941
if err != nil {
4042
log.Fatal(err)

cmd/freegeoip/ansible-playbook/freegeoip.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
- redis
1111
vars:
1212
nodeexporter_url: https://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz
13-
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.2/freegeoip-3.1.2-linux-amd64.tar.gz
13+
freegeoip_url: https://github.com/fiorix/freegeoip/releases/download/v3.1.3/freegeoip-3.1.3-linux-amd64.tar.gz
1414
freegeoip_params:
1515
- -http=:80
1616
- -https=:443

0 commit comments

Comments
 (0)