Put back logs (#2919)

This commit is contained in:
Greg Bergé
2025-03-04 21:33:29 +01:00
committed by GitHub
parent 821899a767
commit 58cd70b0c1
2 changed files with 15 additions and 5 deletions
+11 -3
View File
@@ -129,7 +129,7 @@ export function cache<Args extends any[], Result>(
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<Args extends any[], Result>(
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<Args extends any[], Result>(
);
}
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()) {
+4 -2
View File
@@ -36,7 +36,7 @@ export async function trace<T>(
},
};
const _start = now();
const start = now();
try {
return await fn(span);
} catch (error) {
@@ -44,7 +44,9 @@ export async function trace<T>(
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);
}
}
}