From d17526f8ac0c5fa2d60fe12f8e25d20094fcd542 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Tue, 11 May 2021 11:17:45 +0300 Subject: [PATCH] [#493] logger: Abolish non-usable options Change logger's encoding to `console`, time encoding to `ISO8601TimeEncoder` and leave all other options as they are in `zap.NewProductionConfig`. Remove default values of no longer existing options in node/ir config. Signed-off-by: Leonard Lyubich --- cmd/neofs-ir/defaults.go | 5 ---- cmd/neofs-node/config.go | 10 +------- pkg/util/logger/logger.go | 49 ++++----------------------------------- 3 files changed, 5 insertions(+), 59 deletions(-) diff --git a/cmd/neofs-ir/defaults.go b/cmd/neofs-ir/defaults.go index 53bc8519..c245654b 100644 --- a/cmd/neofs-ir/defaults.go +++ b/cmd/neofs-ir/defaults.go @@ -34,11 +34,6 @@ func newConfig(path string) (*viper.Viper, error) { func defaultConfiguration(cfg *viper.Viper) { cfg.SetDefault("logger.level", "info") - cfg.SetDefault("logger.format", "console") - cfg.SetDefault("logger.trace_level", "fatal") - cfg.SetDefault("logger.no_disclaimer", false) - cfg.SetDefault("logger.sampling.initial", 1000) - cfg.SetDefault("logger.sampling.thereafter", 1000) cfg.SetDefault("pprof.enabled", false) cfg.SetDefault("pprof.address", ":6060") diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index c7bc59a5..af244d3e 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -52,11 +52,7 @@ import ( const ( // logger keys - cfgLogLevel = "logger.level" - cfgLogFormat = "logger.format" - cfgLogTrace = "logger.trace_level" - cfgLogInitSampling = "logger.sampling.initial" - cfgLogThereafterSampling = "logger.sampling.thereafter" + cfgLogLevel = "logger.level" // pprof keys cfgProfilerEnable = "pprof.enabled" @@ -490,10 +486,6 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgNetmapWorkerPoolSize, 10) v.SetDefault(cfgLogLevel, "info") - v.SetDefault(cfgLogFormat, "console") - v.SetDefault(cfgLogTrace, "fatal") - v.SetDefault(cfgLogInitSampling, 1000) - v.SetDefault(cfgLogThereafterSampling, 1000) v.SetDefault(cfgProfilerEnable, false) v.SetDefault(cfgProfilerAddr, ":6060") diff --git a/pkg/util/logger/logger.go b/pkg/util/logger/logger.go index da0de1b0..7f0da8e9 100644 --- a/pkg/util/logger/logger.go +++ b/pkg/util/logger/logger.go @@ -16,14 +16,6 @@ import ( // go.uber.org/zap.Logger. type Logger = zap.Logger -const ( - formatJSON = "json" - formatConsole = "console" - - defaultSamplingInitial = 100 - defaultSamplingThereafter = 100 -) - // ErrNilLogger is returned by functions that // expect a non-nil Logger, but received nil. var ErrNilLogger = errors.New("logger is nil") @@ -31,51 +23,18 @@ var ErrNilLogger = errors.New("logger is nil") // NewLogger is a logger's constructor. func NewLogger(v *viper.Viper) (*Logger, error) { c := zap.NewProductionConfig() - - c.OutputPaths = []string{"stdout"} - c.ErrorOutputPaths = []string{"stdout"} - - if v.IsSet("logger.sampling") { - c.Sampling = &zap.SamplingConfig{ - Initial: defaultSamplingInitial, - Thereafter: defaultSamplingThereafter, - } - - if val := v.GetInt("logger.sampling.initial"); val > 0 { - c.Sampling.Initial = val - } - - if val := v.GetInt("logger.sampling.thereafter"); val > 0 { - c.Sampling.Thereafter = val - } - } - - // logger level c.Level = safeLevel(v.GetString("logger.level")) - traceLvl := safeLevel(v.GetString("logger.trace_level")) - - // logger format - switch f := v.GetString("logger.format"); strings.ToLower(f) { - case formatConsole: - c.Encoding = formatConsole - default: - c.Encoding = formatJSON - } - - // logger time + c.Encoding = "console" c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder l, err := c.Build( - // enable trace only for current log-level - zap.AddStacktrace(traceLvl)) + // record a stack trace for all messages at or above fatal level + zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)), + ) if err != nil { return nil, err } - if v.GetBool("logger.no_disclaimer") { - return l, nil - } - name := v.GetString("app.name") version := v.GetString("app.version")