From 58cd70b0c16721c873ce017a4fcfc45d649fce9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Tue, 4 Mar 2025 21:33:29 +0100 Subject: [PATCH] Put back logs (#2919) --- packages/gitbook/src/lib/cache/cache.ts | 14 +++++++++++--- packages/gitbook/src/lib/tracing.ts | 6 ++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/gitbook/src/lib/cache/cache.ts b/packages/gitbook/src/lib/cache/cache.ts index 38af01344..1a1c8fcb2 100644 --- a/packages/gitbook/src/lib/cache/cache.ts +++ b/packages/gitbook/src/lib/cache/cache.ts @@ -129,7 +129,7 @@ export function cache( async (key: string, signal: AbortSignal | undefined, span: TraceSpan, ...args: Args) => { const timeStart = now(); let readCacheDuration = 0; - let _fetchDuration = 0; + let fetchDuration = 0; let result: readonly [CacheEntry, string] | null = null; const tag = cacheDef.tag?.(...args); @@ -179,7 +179,7 @@ export function cache( const upstream = await revalidate(key, fallbackOps.signal, ...args); readCacheDuration = timeFetch - timeStart; - _fetchDuration = now() - timeFetch; + fetchDuration = now() - timeFetch; return [upstream, 'fetch'] as const; }, @@ -219,10 +219,18 @@ export function cache( ); } - const _totalDuration = now() - timeStart; + const totalDuration = now() - timeStart; // Log if (process.env.SILENT !== 'true') { + // biome-ignore lint/suspicious/noConsole: we want to log here + console.log( + `cache: ${key} ${cacheStatus}${ + cacheStatus === 'hit' ? ` on ${backendName}` : '' + } in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed( + 0 + )}ms, read in ${readCacheDuration.toFixed(0)}ms` + ); } if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) { diff --git a/packages/gitbook/src/lib/tracing.ts b/packages/gitbook/src/lib/tracing.ts index b4e7343fc..c2709bfa2 100644 --- a/packages/gitbook/src/lib/tracing.ts +++ b/packages/gitbook/src/lib/tracing.ts @@ -36,7 +36,7 @@ export async function trace( }, }; - const _start = now(); + const start = now(); try { return await fn(span); } catch (error) { @@ -44,7 +44,9 @@ export async function trace( throw error; } finally { if (process.env.SILENT !== 'true') { - const _end = now(); + const end = now(); + // biome-ignore lint/suspicious/noConsole: we want to log performance data + console.log(`trace ${completeName} ${end - start}ms`, attributes); } } }