@@ -227,7 +227,7 @@ func (h handler) asyncCacheRevalidate(key string, orig *http.Request) func() {
227
227
req .Header = cloneHeaders (orig .Header )
228
228
stripHopByHop (req .Header )
229
229
req .Header .Del ("Range" )
230
- log .Ctx (orig .Context ()).Debug ().Str ("key " , key ). Str ( "url" , u . String () ).Msg ("revalidating cache" )
230
+ log .Ctx (orig .Context ()).Debug ().Str ("cachKey " , key ).Msg ("revalidating cache" )
231
231
232
232
resp , err := h .httpClient .Do (req )
233
233
if err != nil {
@@ -243,7 +243,13 @@ func (h handler) asyncCacheRevalidate(key string, orig *http.Request) func() {
243
243
}
244
244
245
245
func (h handler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
246
- logger := log .With ().Str ("path" , r .URL .Path ).Str ("method" , r .Method ).Logger ()
246
+ logger := log .With ().Fields (map [string ]any {
247
+ "request" : map [string ]any {
248
+ "path" : r .URL .Path ,
249
+ "method" : strings .ToLower (r .Method ),
250
+ "queryParams" : r .URL .Query ().Encode (),
251
+ },
252
+ }).Logger ()
247
253
ctx := logger .WithContext (r .Context ())
248
254
249
255
if strings .ToUpper (r .Method ) != http .MethodGet || r .Header .Get ("Range" ) != "" {
@@ -275,7 +281,7 @@ func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
275
281
if entry .IsStale () {
276
282
go h .worker .Start (key , h .asyncCacheRevalidate (key , r ))
277
283
}
278
- logger .Debug ().Str ("key " , key ). Int ( "status" , entry . Status ).Msg ("serving cached response" )
284
+ logger .Debug ().Str ("cacheKey " , key ).Msg ("serving cached response" )
279
285
serveResponseFromMemory (w , * entry )
280
286
}
281
287
@@ -288,6 +294,7 @@ func (h handler) cacheResponse(ctx context.Context, key string) func(*http.Respo
288
294
return nil
289
295
}
290
296
if ! (resp .StatusCode == http .StatusOK || resp .StatusCode == http .StatusNoContent ) {
297
+ lg .Debug ().Str ("cacheKey" , key ).Int ("status" , resp .StatusCode ).Msg ("skipping cache: not 200 or 204" )
291
298
return nil
292
299
}
293
300
// TODO: add cache control back in
@@ -299,7 +306,7 @@ func (h handler) cacheResponse(ctx context.Context, key string) func(*http.Respo
299
306
return nil
300
307
}
301
308
302
- lg .Debug ().Str ("key " , key ). Int ( "status" , resp . StatusCode ).Msg ("caching response" )
309
+ lg .Debug ().Str ("cacheKey " , key ).Msg ("caching response" )
303
310
304
311
lr := & io.LimitedReader {R : resp .Body , N : maxCacheBytes + 1 }
305
312
body , err := io .ReadAll (lr )
0 commit comments