Created
March 4, 2024 10:11
-
-
Save disintegrator/9c9d07f2baca62b3c4cf032791553b17 to your computer and use it in GitHub Desktop.
DiscardHandler for log/slog in Go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package log | |
import ( | |
"context" | |
"log/slog" | |
) | |
// A DiscardHandler discards all log records. | |
type DiscardHandler struct{} | |
// Enabled implements Handler.Enabled by reporting whether | |
// level is at least as large as h's level. | |
func (h *DiscardHandler) Enabled(context.Context, slog.Level) bool { | |
return false | |
} | |
// Handle implements Handler.Handle. | |
func (h *DiscardHandler) Handle(context.Context, slog.Record) error { | |
return nil | |
} | |
// WithAttrs implements Handler.WithAttrs. | |
func (h *DiscardHandler) WithAttrs([]slog.Attr) slog.Handler { | |
return h | |
} | |
// WithGroup implements Handler.WithGroup. | |
func (h *DiscardHandler) WithGroup(string) slog.Handler { | |
return h | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment