frostfs-node/pkg/util/logger/test/logger.go
Pavel Karpy f037022a7a [#1770] logger: Refactor Logger component
Make it store its internal `zap.Logger`'s level. Also, make all the
components to accept internal `logger.Logger` instead of `zap.Logger`; it
will simplify future refactor.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
2022-10-12 18:11:05 +03:00

36 lines
659 B
Go

package test
import (
"github.com/nspcc-dev/neofs-node/pkg/util/logger"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
const sampling = 1000
// NewLogger creates a new logger.
//
// If debug, development logger is created.
func NewLogger(debug bool) *logger.Logger {
var l logger.Logger
l.Logger = zap.L()
if debug {
cfg := zap.NewDevelopmentConfig()
cfg.Sampling = &zap.SamplingConfig{
Initial: sampling,
Thereafter: sampling,
}
cfg.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
log, err := cfg.Build()
if err != nil {
panic("could not prepare logger: " + err.Error())
}
l.Logger = log
}
return &l
}