From 556477ca9df3fa2e5939057861314eabe5ce30ca Mon Sep 17 00:00:00 2001 From: Valery Piashchynski Date: Fri, 30 Apr 2021 16:04:55 +0300 Subject: - Make development log colored - Remove old TODOs Signed-off-by: Valery Piashchynski --- plugins/kv/drivers/boltdb/driver.go | 2 -- plugins/logger/config.go | 30 +++++++++++++++++++++++++----- plugins/reload/watcher.go | 3 +-- 3 files changed, 26 insertions(+), 9 deletions(-) (limited to 'plugins') diff --git a/plugins/kv/drivers/boltdb/driver.go b/plugins/kv/drivers/boltdb/driver.go index b596d4c3..2e2df527 100644 --- a/plugins/kv/drivers/boltdb/driver.go +++ b/plugins/kv/drivers/boltdb/driver.go @@ -401,8 +401,6 @@ func (d *Driver) startGCLoop() { //nolint:gocognit }) if err != nil { d.log.Error("error during the gc phase of update", "error", err) - // todo this error is ignored, it means, that timer still be active - // to prevent this, we need to invoke t.Stop() return false } } diff --git a/plugins/logger/config.go b/plugins/logger/config.go index c435e8be..d2236cac 100644 --- a/plugins/logger/config.go +++ b/plugins/logger/config.go @@ -40,7 +40,7 @@ type Config struct { ErrorOutput []string `mapstructure:"errorOutput"` } -// ZapConfig converts config into Zap configuration. +// BuildLogger converts config into Zap configuration. func (cfg *Config) BuildLogger() (*zap.Logger, error) { var zCfg zap.Config switch strings.ToLower(cfg.Mode) { @@ -49,7 +49,29 @@ func (cfg *Config) BuildLogger() (*zap.Logger, error) { case "production": zCfg = zap.NewProductionConfig() case "development": - zCfg = zap.NewDevelopmentConfig() + zCfg = zap.Config{ + Level: zap.NewAtomicLevelAt(zap.DebugLevel), + Development: true, + Encoding: "console", + EncoderConfig: zapcore.EncoderConfig{ + // Keys can be anything except the empty string. + TimeKey: "T", + LevelKey: "L", + NameKey: "N", + CallerKey: "C", + FunctionKey: zapcore.OmitKey, + MessageKey: "M", + StacktraceKey: "S", + LineEnding: zapcore.DefaultLineEnding, + EncodeLevel: ColoredLevelEncoder, + EncodeTime: zapcore.ISO8601TimeEncoder, + EncodeDuration: zapcore.StringDurationEncoder, + EncodeCaller: zapcore.ShortCallerEncoder, + EncodeName: ColoredNameEncoder, + }, + OutputPaths: []string{"stderr"}, + ErrorOutputPaths: []string{"stderr"}, + } case "raw": zCfg = zap.Config{ Level: zap.NewAtomicLevelAt(zap.InfoLevel), @@ -98,12 +120,10 @@ func (cfg *Config) BuildLogger() (*zap.Logger, error) { zCfg.ErrorOutputPaths = cfg.ErrorOutput } - // todo: - return zCfg.Build() } -// Initialize default logger +// InitDefault Initialize default logger func (cfg *Config) InitDefault() { if cfg.Mode == "" { cfg.Mode = "development" diff --git a/plugins/reload/watcher.go b/plugins/reload/watcher.go index 1b3407e5..421668b3 100644 --- a/plugins/reload/watcher.go +++ b/plugins/reload/watcher.go @@ -216,9 +216,8 @@ func (w *Watcher) waitEvent(d time.Duration) error { case <-ticker.C: // this is not very effective way // because we have to wait on Lock - // better is to listen files in parallel, but, since that would be used in debug... TODO + // better is to listen files in parallel, but, since that would be used in debug... for serviceName := range w.watcherConfigs { - // TODO sync approach fileList, _ := w.retrieveFileList(serviceName, w.watcherConfigs[serviceName]) w.pollEvents(w.watcherConfigs[serviceName].ServiceName, fileList) } -- cgit v1.2.3