Skip to content

Commit

Permalink
fix: add a discarding Logger to the client by default
Browse files Browse the repository at this point in the history
  • Loading branch information
masonkatz committed Feb 21, 2024
1 parent 5b6891e commit 8a07442
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func New(o *Options) *Client {
BaseURL: fmt.Sprintf("https://%s", o.Address),
Username: o.Username,
Password: o.Password,
Logger: slog.New(discardHandler{}),
NewError: newDefaultError,
}
}
Expand Down Expand Up @@ -299,3 +300,13 @@ func newDefaultError(code int, r io.Reader) error {

return &defaultError{Code: code, Body: b.String()}
}

// TODO: something very much like this will eventually be in the slog package (go 1.23 or later).

// discardHandler is a slog.Handler that discards all log records.
type discardHandler struct{}

func (discardHandler) Enabled(context.Context, slog.Level) bool { return false }
func (discardHandler) Handle(context.Context, slog.Record) error { return nil }
func (d discardHandler) WithAttrs([]slog.Attr) slog.Handler { return d }
func (d discardHandler) WithGroup(string) slog.Handler { return d }

0 comments on commit 8a07442

Please sign in to comment.