Skip to content

Commit

Permalink
feat: add promslog.NewNopLogger() convenience func (#697)
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](#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 authored Sep 27, 2024
1 parent d66e745 commit 4e3a6fd
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 4e3a6fd

Please sign in to comment.