Skip to content

Commit

Permalink
Make log timestamps optional; new version
Browse files Browse the repository at this point in the history
On systemd we had duplicated timestamps so they're optional now.
  • Loading branch information
fiorix committed Mar 15, 2016
1 parent 7969483 commit 034015a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 7 additions & 1 deletion apiserver/config.go
Expand Up @@ -31,6 +31,7 @@ type Config struct {
UseXForwardedFor bool UseXForwardedFor bool
Silent bool Silent bool
LogToStdout bool LogToStdout bool
LogTimestamp bool
RedisAddr string RedisAddr string
RedisTimeout time.Duration RedisTimeout time.Duration
MemcacheAddr string MemcacheAddr string
Expand All @@ -57,6 +58,7 @@ func NewConfig() *Config {
DB: freegeoip.MaxMindDB, DB: freegeoip.MaxMindDB,
UpdateInterval: 24 * time.Hour, UpdateInterval: 24 * time.Hour,
RetryInterval: 2 * time.Hour, RetryInterval: 2 * time.Hour,
LogTimestamp: true,
RedisAddr: "localhost:6379", RedisAddr: "localhost:6379",
RedisTimeout: time.Second, RedisTimeout: time.Second,
MemcacheAddr: "localhost:11211", MemcacheAddr: "localhost:11211",
Expand All @@ -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.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.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.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.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.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") fs.StringVar(&c.MemcacheAddr, "memcache", c.MemcacheAddr, "Memcache address in form of host:port[,host:port] for quota")
Expand All @@ -101,7 +104,10 @@ func (c *Config) logWriter() io.Writer {
} }


func (c *Config) errorLogger() *log.Logger { 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 { func (c *Config) accessLogger() *log.Logger {
Expand Down
6 changes: 4 additions & 2 deletions apiserver/main.go
Expand Up @@ -19,7 +19,7 @@ import (
) )


// Version tag. // Version tag.
var Version = "3.1.2" var Version = "3.1.3"


// Run is the entrypoint for the freegeoip server. // Run is the entrypoint for the freegeoip server.
func Run() { func Run() {
Expand All @@ -34,7 +34,9 @@ func Run() {
if c.LogToStdout { if c.LogToStdout {
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
} }
log.SetPrefix("[freegeoip] ") if !c.LogTimestamp {
log.SetFlags(0)
}
f, err := NewHandler(c) f, err := NewHandler(c)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/freegeoip/ansible-playbook/freegeoip.yml
Expand Up @@ -10,7 +10,7 @@
- redis - redis
vars: vars:
nodeexporter_url: http://github.com/prometheus/node_exporter/releases/download/0.11.0/node_exporter-0.11.0.linux-amd64.tar.gz 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: freegeoip_params:
- -http=:80 - -http=:80
- -https=:443 - -https=:443
Expand Down

0 comments on commit 034015a

Please sign in to comment.