From baaff0f8319347648822b2a73f859797a445ead7 Mon Sep 17 00:00:00 2001 From: Marc Bernard <59966492+mbtools@users.noreply.github.com> Date: Thu, 10 Oct 2024 12:51:32 -0400 Subject: [PATCH] chore: log cache hits distinct from fetch --- lib/check-response.js | 16 ++++++++++++---- test/check-response.js | 4 ++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/check-response.js b/lib/check-response.js index 65eea296..2f183082 100644 --- a/lib/check-response.js +++ b/lib/check-response.js @@ -48,10 +48,18 @@ function logRequest (method, res, startTime) { const cacheStr = cacheStatus ? ` (cache ${cacheStatus})` : '' const urlStr = cleanUrl(res.url) - log.http( - 'fetch', - `${method.toUpperCase()} ${res.status} ${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}` - ) + // If make-fetch-happen reports a cache hit, then there was no fetch + if (cacheStatus === 'hit') { + log.http( + 'cache', + `${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}` + ) + } else { + log.http( + 'fetch', + `${method.toUpperCase()} ${res.status} ${urlStr} ${elapsedTime}ms${attemptStr}${cacheStr}` + ) + } } function checkErrors (method, res, startTime, opts) { diff --git a/test/check-response.js b/test/check-response.js index 736ddd21..e619ef1e 100644 --- a/test/check-response.js +++ b/test/check-response.js @@ -224,9 +224,9 @@ t.test('logs the value of x-local-cache-status when set', t => { startTime, }) res.body.emit('end') - t.equal(header, 'fetch') + t.equal(header, 'cache') t.match( msg, - /^GET 200 http:\/\/username:\*\*\*@example.com\/foo\/bar\/baz [0-9]+m?s \(cache hit\)$/ + /^http:\/\/username:\*\*\*@example.com\/foo\/bar\/baz [0-9]+m?s \(cache hit\)$/ ) })