updates #207
| @@ -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) | ||||
| } | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user