Skip to content

Commit

Permalink
Add slog adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekSi committed Nov 28, 2024
1 parent 1d148ff commit 66aaeda
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions transport.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gh

import (
"fmt"
"log/slog"
"net/http"
"net/http/httputil"
)
Expand All @@ -11,6 +13,13 @@ type Printf func(format string, args ...any)
// NoopPrintf is a Printf function that does nothing.
func NoopPrintf(string, ...any) {}

// SLogPrintf is a Printf function that uses given slog.Logger with Debug level.
func SLogPrintf(l *slog.Logger) Printf {
return func(format string, args ...any) {
l.Debug(fmt.Sprintf(format, args...))
}
}

// transport is an http.RoundTripper with debug logging.
type transport struct {
t http.RoundTripper
Expand Down

0 comments on commit 66aaeda

Please sign in to comment.