git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/log/slogx/discard_handler.go (about) 1 package slogx 2 3 import ( 4 "context" 5 "log/slog" 6 ) 7 8 type DiscardHandler struct { 9 } 10 11 // NewDiscardHandler returns a new DiscardHandler that do nothing and discards logs 12 func NewDiscardHandler() *DiscardHandler { 13 return &DiscardHandler{} 14 } 15 16 func (handler *DiscardHandler) Enabled(_ context.Context, _ slog.Level) bool { 17 return true 18 } 19 20 func (handler *DiscardHandler) Handle(_ context.Context, _ slog.Record) error { 21 return nil 22 } 23 24 func (handler *DiscardHandler) WithAttrs(attrs []slog.Attr) slog.Handler { 25 return handler 26 } 27 28 func (handler *DiscardHandler) WithGroup(name string) slog.Handler { 29 return handler 30 }