X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/c14246b9a21d038fc6fa850f4032659a98397784..fd717a88835be62ae1b5c4b1ecd74c21cab0e744:/services/keepstore/config.go diff --git a/services/keepstore/config.go b/services/keepstore/config.go index dc06ef5498..83dd84ecc0 100644 --- a/services/keepstore/config.go +++ b/services/keepstore/config.go @@ -5,17 +5,19 @@ import ( "encoding/json" "fmt" "io/ioutil" - "log" "strings" "time" "git.curoverse.com/arvados.git/sdk/go/arvados" + log "github.com/Sirupsen/logrus" ) type Config struct { Debug bool Listen string + LogFormat string + PIDFile string MaxBuffers int @@ -38,10 +40,13 @@ type Config struct { var theConfig = DefaultConfig() +const rfc3339NanoFixed = "2006-01-02T15:04:05.000000000Z07:00" + // DefaultConfig returns the default configuration. func DefaultConfig() *Config { return &Config{ Listen: ":25107", + LogFormat: "json", MaxBuffers: 128, RequireSignatures: true, BlobSignatureTTL: arvados.Duration(14 * 24 * time.Hour), @@ -55,12 +60,27 @@ func DefaultConfig() *Config { // fields, and before using the config. func (cfg *Config) Start() error { if cfg.Debug { + log.SetLevel(log.DebugLevel) cfg.debugLogf = log.Printf cfg.debugLogf("debugging enabled") } else { cfg.debugLogf = func(string, ...interface{}) {} } + switch strings.ToLower(cfg.LogFormat) { + case "text": + log.SetFormatter(&log.TextFormatter{ + FullTimestamp: true, + TimestampFormat: rfc3339NanoFixed, + }) + case "json": + log.SetFormatter(&log.JSONFormatter{ + TimestampFormat: rfc3339NanoFixed, + }) + default: + return fmt.Errorf(`unsupported log format %q (try "text" or "json")`, cfg.LogFormat) + } + if cfg.MaxBuffers < 0 { return fmt.Errorf("MaxBuffers must be greater than zero") }