Skip to content

Commit

Permalink
feat: add promslog.NewNopLogger() convenience func
Browse files Browse the repository at this point in the history
Simple convenience function to return an slog.Logger that writes to
io.Discard. Originally suggested by @ArthurSens
[here](prometheus#686 (comment)),
and requested again by @bboreham
[here](prometheus/prometheus#14906 (comment)).
As Bryan points out in the comment, there's 147 instances where a
discard logger is needed, so a consistent utility function to manage
them seems helpful.

Signed-off-by: TJ Hoplock <t.hoplock@gmail.com>
  • Loading branch information
tjhop committed Sep 27, 2024
1 parent d66e745 commit f157166
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions promslog/slog.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,9 @@ func New(config *Config) *slog.Logger {
}
return slog.New(slog.NewTextHandler(config.Writer, logHandlerOpts))
}

// NewNopLogger is a convenience function to return an slog.Logger that writes
// to io.Discard.
func NewNopLogger() *slog.Logger {
return slog.New(slog.NewTextHandler(io.Discard, nil))
}

0 comments on commit f157166

Please sign in to comment.