diff --git a/logger/slog/slog.go b/logger/slog/slog.go index 4923e6a5..8a4260f1 100644 --- a/logger/slog/slog.go +++ b/logger/slog/slog.go @@ -171,7 +171,19 @@ func (s *slogLogger) Init(opts ...logger.Option) error { } attrs, _ := s.argsAttrs(s.opts.Fields) - s.handler = &wrapper{h: slog.NewJSONHandler(s.opts.Out, handleOpt).WithAttrs(attrs)} + + var h slog.Handler + if s.opts.Context != nil { + if v, ok := s.opts.Context.Value(handlerKey{}).(slog.Handler); ok && v != nil { + h = v + } + } + + if h == nil { + h = slog.NewJSONHandler(s.opts.Out, handleOpt) + } + + s.handler = &wrapper{h: h.WithAttrs(attrs)} s.handler.level.Store(int64(loggerToSlogLevel(s.opts.Level))) s.mu.Unlock() @@ -329,3 +341,9 @@ func (s *slogLogger) argsAttrs(args []interface{}) ([]slog.Attr, error) { return attrs, err } + +type handlerKey struct{} + +func WithHandler(h slog.Handler) logger.Option { + return logger.SetOption(handlerKey{}, h) +} diff --git a/store/store.go b/store/store.go index fcd0c987..d93b58d3 100644 --- a/store/store.go +++ b/store/store.go @@ -10,7 +10,7 @@ import ( var ( ErrWatcherStopped = errors.New("watcher stopped") // ErrNotConnected is returned when a store is not connected - ErrNotConnected = errors.New("not conected") + ErrNotConnected = errors.New("not connected") // ErrNotFound is returned when a key doesn't exist ErrNotFound = errors.New("not found") // ErrInvalidKey is returned when a key has empty or have invalid format