Skip to content

Instantly share code, notes, and snippets.

@disintegrator
Created March 4, 2024 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save disintegrator/9c9d07f2baca62b3c4cf032791553b17 to your computer and use it in GitHub Desktop.
Save disintegrator/9c9d07f2baca62b3c4cf032791553b17 to your computer and use it in GitHub Desktop.
DiscardHandler for log/slog in Go
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