[#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>
This commit is contained in:
Pavel Karpy 2022-09-28 10:41:01 +03:00 committed by Pavel Karpy
parent 4baf00aa21
commit f037022a7a
83 changed files with 207 additions and 156 deletions

View file

@ -9,10 +9,10 @@ import (
// Logger represents a component
// for writing messages to log.
//
// It is a type alias of
// go.uber.org/zap.Logger.
type Logger = zap.Logger
type Logger struct {
*zap.Logger
lvl zap.AtomicLevel
}
// Prm groups Logger's parameters.
type Prm struct {
@ -40,12 +40,19 @@ func (p *Prm) SetLevelString(s string) error {
//
// Logger records a stack trace for all messages at or above fatal level.
func NewLogger(prm Prm) (*Logger, error) {
lvl := zap.NewAtomicLevelAt(prm.level)
c := zap.NewProductionConfig()
c.Level = zap.NewAtomicLevelAt(prm.level)
c.Level = lvl
c.Encoding = "console"
c.EncoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
return c.Build(
l, err := c.Build(
zap.AddStacktrace(zap.NewAtomicLevelAt(zap.FatalLevel)),
)
if err != nil {
return nil, err
}
return &Logger{Logger: l, lvl: lvl}, nil
}