Skip to content

Commit 58cd70b

Browse files
authored
Put back logs (#2919)
1 parent 821899a commit 58cd70b

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

packages/gitbook/src/lib/cache/cache.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ export function cache<Args extends any[], Result>(
129129
async (key: string, signal: AbortSignal | undefined, span: TraceSpan, ...args: Args) => {
130130
const timeStart = now();
131131
let readCacheDuration = 0;
132-
let _fetchDuration = 0;
132+
let fetchDuration = 0;
133133

134134
let result: readonly [CacheEntry, string] | null = null;
135135
const tag = cacheDef.tag?.(...args);
@@ -179,7 +179,7 @@ export function cache<Args extends any[], Result>(
179179
const upstream = await revalidate(key, fallbackOps.signal, ...args);
180180

181181
readCacheDuration = timeFetch - timeStart;
182-
_fetchDuration = now() - timeFetch;
182+
fetchDuration = now() - timeFetch;
183183
return [upstream, 'fetch'] as const;
184184
},
185185

@@ -219,10 +219,18 @@ export function cache<Args extends any[], Result>(
219219
);
220220
}
221221

222-
const _totalDuration = now() - timeStart;
222+
const totalDuration = now() - timeStart;
223223

224224
// Log
225225
if (process.env.SILENT !== 'true') {
226+
// biome-ignore lint/suspicious/noConsole: we want to log here
227+
console.log(
228+
`cache: ${key} ${cacheStatus}${
229+
cacheStatus === 'hit' ? ` on ${backendName}` : ''
230+
} in total ${totalDuration.toFixed(0)}ms, fetch in ${fetchDuration.toFixed(
231+
0
232+
)}ms, read in ${readCacheDuration.toFixed(0)}ms`
233+
);
226234
}
227235

228236
if (savedEntry.meta.revalidatesAt && savedEntry.meta.revalidatesAt < Date.now()) {

packages/gitbook/src/lib/tracing.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,17 @@ export async function trace<T>(
3636
},
3737
};
3838

39-
const _start = now();
39+
const start = now();
4040
try {
4141
return await fn(span);
4242
} catch (error) {
4343
span.setAttribute('error', true);
4444
throw error;
4545
} finally {
4646
if (process.env.SILENT !== 'true') {
47-
const _end = now();
47+
const end = now();
48+
// biome-ignore lint/suspicious/noConsole: we want to log performance data
49+
console.log(`trace ${completeName} ${end - start}ms`, attributes);
4850
}
4951
}
5052
}

0 commit comments

Comments
 (0)