From 85c222b39a9f49a186cb3d70d2b149e1f7150c0e Mon Sep 17 00:00:00 2001 From: Joel Robotham Date: Tue, 17 Mar 2026 15:18:52 +1100 Subject: [PATCH] refactor: use structured log attributes instead of fmt.Sprintf Amp-Thread-ID: https://ampcode.com/threads/T-019ce5cd-b9eb-77c8-a7b5-c2b819e60102 Co-authored-by: Amp Amp-Thread-ID: https://ampcode.com/threads/T-019ce5cd-b9eb-77c8-a7b5-c2b819e60102 Co-authored-by: Amp --- internal/httputil/logging.go | 3 +-- internal/strategy/git/git.go | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/httputil/logging.go b/internal/httputil/logging.go index 8eeae13..aad2d1e 100644 --- a/internal/httputil/logging.go +++ b/internal/httputil/logging.go @@ -1,7 +1,6 @@ package httputil import ( - "fmt" "net/http" "github.com/block/cachew/internal/logging" @@ -10,7 +9,7 @@ import ( func LoggingMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Propagate attributes tot the handlers. - logger := logging.FromContext(r.Context()).With("request", fmt.Sprintf("%s %s", r.Method, r.RequestURI)) + logger := logging.FromContext(r.Context()).With("method", r.Method, "uri", r.RequestURI) r = r.WithContext(logging.ContextWithLogger(r.Context(), logger)) logger.Debug("Request received") next.ServeHTTP(w, r) diff --git a/internal/strategy/git/git.go b/internal/strategy/git/git.go index 11b3cc5..c153d67 100644 --- a/internal/strategy/git/git.go +++ b/internal/strategy/git/git.go @@ -581,7 +581,8 @@ func (s *Strategy) doFetch(ctx context.Context, repo *gitclone.Repository) error start := time.Now() if err := repo.Fetch(ctx); err != nil { - return errors.Errorf("fetch failed in %s: %w", time.Since(start), err) + logger.ErrorContext(ctx, "Fetch failed", "upstream", repo.UpstreamURL(), "duration", time.Since(start), "error", err) + return errors.Errorf("fetch failed: %w", err) } logger.InfoContext(ctx, "Fetch completed", "upstream", repo.UpstreamURL(), "duration", time.Since(start)) return nil