this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

library package go-log to slog update (#523)

These packages emit log lines from all kinds of services, even those not
using go-log, and they end up formatted inconsistently (lines not JSON).

authored by

bnewbold and committed by
GitHub
c0816814 fa392e38

+16 -19
+3 -5
api/extra.go
··· 5 5 "errors" 6 6 "fmt" 7 7 "io" 8 + "log/slog" 8 9 "net" 9 10 "net/http" 10 11 "net/url" ··· 14 15 15 16 "github.com/bluesky-social/indigo/did" 16 17 arc "github.com/hashicorp/golang-lru/arc/v2" 17 - logging "github.com/ipfs/go-log" 18 18 "go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" 19 19 otel "go.opentelemetry.io/otel" 20 20 ) 21 - 22 - var log = logging.Logger("api") 23 21 24 22 func ResolveDidToHandle(ctx context.Context, res did.Resolver, hr HandleResolver, udid string) (string, string, error) { 25 23 ctx, span := otel.Tracer("gosky").Start(ctx, "resolveDidToHandle") ··· 248 246 249 247 resp, err := c.Do(req) 250 248 if err != nil { 251 - log.Warnf("failed to get did: %s", err) 249 + slog.Warn("failed to resolve handle to DID", "handle", handle, "err", err) 252 250 continue 253 251 } 254 252 255 253 if resp.StatusCode != 200 { 256 - log.Warnf("got non-200 status code while fetching did: %d", resp.StatusCode) 254 + slog.Warn("got non-200 status code while resolving handle", "handle", handle, "statusCode", resp.StatusCode) 257 255 continue 258 256 } 259 257
+13 -14
util/http.go
··· 2 2 3 3 import ( 4 4 "context" 5 + "log/slog" 5 6 "net/http" 6 7 "time" 7 8 8 9 "github.com/hashicorp/go-retryablehttp" 9 - logging "github.com/ipfs/go-log" 10 10 ) 11 11 12 - var log = logging.Logger("http") 13 - 14 - type LeveledZap struct { 15 - inner *logging.ZapEventLogger 12 + type LeveledSlog struct { 13 + inner *slog.Logger 16 14 } 17 15 18 16 // re-writes HTTP client ERROR to WARN level (because of retries) 19 - func (l LeveledZap) Error(msg string, keysAndValues ...interface{}) { 20 - l.inner.Warnw(msg, keysAndValues...) 17 + func (l LeveledSlog) Error(msg string, keysAndValues ...interface{}) { 18 + l.inner.Warn(msg, keysAndValues...) 21 19 } 22 20 23 - func (l LeveledZap) Warn(msg string, keysAndValues ...interface{}) { 24 - l.inner.Warnw(msg, keysAndValues...) 21 + func (l LeveledSlog) Warn(msg string, keysAndValues ...interface{}) { 22 + l.inner.Warn(msg, keysAndValues...) 25 23 } 26 24 27 - func (l LeveledZap) Info(msg string, keysAndValues ...interface{}) { 28 - l.inner.Infow(msg, keysAndValues...) 25 + func (l LeveledSlog) Info(msg string, keysAndValues ...interface{}) { 26 + l.inner.Info(msg, keysAndValues...) 29 27 } 30 28 31 - func (l LeveledZap) Debug(msg string, keysAndValues ...interface{}) { 32 - l.inner.Debugw(msg, keysAndValues...) 29 + func (l LeveledSlog) Debug(msg string, keysAndValues ...interface{}) { 30 + l.inner.Debug(msg, keysAndValues...) 33 31 } 34 32 35 33 // Generates an HTTP client with decent general-purpose defaults around ··· 45 43 // default. 46 44 func RobustHTTPClient() *http.Client { 47 45 46 + logger := LeveledSlog{inner: slog.Default().With("subsystem", "RobustHTTPClient")} 48 47 retryClient := retryablehttp.NewClient() 49 48 retryClient.RetryMax = 3 50 49 retryClient.RetryWaitMin = 1 * time.Second 51 50 retryClient.RetryWaitMax = 10 * time.Second 52 - retryClient.Logger = retryablehttp.LeveledLogger(LeveledZap{log}) 51 + retryClient.Logger = retryablehttp.LeveledLogger(logger) 53 52 retryClient.CheckRetry = XRPCRetryPolicy 54 53 client := retryClient.StandardClient() 55 54 client.Timeout = 30 * time.Second