Add detailed logging for image requests with cache status and timing

This commit is contained in:
2026-01-08 05:04:08 -08:00
parent 6a20406b0f
commit 1a97f42cd8
3 changed files with 18 additions and 0 deletions

View File

@@ -78,7 +78,11 @@ func (s *Handlers) HandleImage() http.HandlerFunc {
return
}
// Get cache key for logging
cacheKey := imgcache.CacheKey(req)
// Get the image (from cache or fetch/process)
startTime := time.Now()
resp, err := s.imgSvc.Get(ctx, req)
if err != nil {
s.log.Error("failed to get image",
@@ -120,6 +124,17 @@ func (s *Handlers) HandleImage() http.HandlerFunc {
w.Header().Set("ETag", resp.ETag)
}
// Log cache status and timing
duration := time.Since(startTime)
s.log.Info("image served",
"cache_key", cacheKey,
"cache_status", resp.CacheStatus,
"duration_ms", duration.Milliseconds(),
"format", req.Format,
"served_bytes", resp.ContentLength,
"fetched_bytes", resp.FetchedBytes,
)
// Stream the response
w.WriteHeader(http.StatusOK)