[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-05-11 11:17:45 +03:00 committed by Alex Vanin
parent 737a9417d1
commit d17526f8ac
3 changed files with 5 additions and 59 deletions

View file

@ -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")