logger/slog: fix slog
pr / test (pull_request) Successful in 1m24s Details
lint / lint (pull_request) Successful in 10m24s Details

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-03-07 08:19:14 +03:00
parent 34940b68d7
commit 5bec0cef03
1 changed files with 3 additions and 7 deletions

View File

@ -61,7 +61,6 @@ func (s *slogLogger) renameAttr(_ []string, a slog.Attr) slog.Attr {
}
type slogLogger struct {
slog *slog.Logger
leveler *slog.LevelVar
handler slog.Handler
opts logger.Options
@ -88,8 +87,7 @@ func (s *slogLogger) Clone(opts ...logger.Option) logger.Logger {
AddSource: l.opts.AddSource,
}
l.leveler.Set(loggerToSlogLevel(l.opts.Level))
l.slog = slog.New(slog.NewJSONHandler(options.Out, handleOpt)).With(options.Fields...)
l.handler = l.slog.Handler()
l.handler = slog.New(slog.NewJSONHandler(options.Out, handleOpt)).With(options.Fields...).Handler()
return l
}
@ -122,8 +120,7 @@ func (s *slogLogger) Fields(attrs ...interface{}) logger.Logger {
AddSource: l.opts.AddSource,
}
l.slog = slog.New(slog.NewJSONHandler(l.opts.Out, handleOpt)).With(attrs...)
l.handler = l.slog.Handler()
l.handler = slog.New(slog.NewJSONHandler(l.opts.Out, handleOpt)).With(attrs...).Handler()
return l
}
@ -146,8 +143,7 @@ func (s *slogLogger) Init(opts ...logger.Option) error {
AddSource: s.opts.AddSource,
}
s.leveler.Set(loggerToSlogLevel(s.opts.Level))
s.slog = slog.New(slog.NewJSONHandler(s.opts.Out, handleOpt)).With(s.opts.Fields...)
s.handler = s.slog.Handler()
s.handler = slog.New(slog.NewJSONHandler(s.opts.Out, handleOpt)).With(s.opts.Fields...).Handler()
s.mu.Unlock()
return nil