X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/dfe0ec7bfec3fd72cd40d3962e5c8af08d2413d2..0eb72b526bf8bbb011551ecf019f604e17a534f1:/services/keepstore/config.go diff --git a/services/keepstore/config.go b/services/keepstore/config.go index 9c318d1245..19a614a1fa 100644 --- a/services/keepstore/config.go +++ b/services/keepstore/config.go @@ -1,3 +1,7 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + package main import ( @@ -5,16 +9,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 @@ -32,14 +39,18 @@ type Config struct { blobSigningKey []byte systemAuthToken string + debugLogf func(string, ...interface{}) } 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), @@ -52,6 +63,28 @@ func DefaultConfig() *Config { // Start should be called exactly once: after setting all public // 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") }