mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 03:23:02 +00:00
fix: performance logging code
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
import { wrapFunctionCall } from './fnWrapper';
|
||||
|
||||
export function timedLogger<R = unknown>(label: string, fn: () => R): R {
|
||||
if (import.meta.env.ENABLE_PERF_LOG !== '1') {
|
||||
if (import.meta.env.VITE_ENABLE_PERF_LOG !== '1') {
|
||||
return fn();
|
||||
} else {
|
||||
return wrapFunctionCall(
|
||||
() => console.time(label),
|
||||
() => console.timeEnd(label),
|
||||
fn
|
||||
fn,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export function withGroupedLogs<R = unknown>(label: string, fn: () => R): R {
|
||||
if (import.meta.env.ENABLE_PERF_LOG !== '1') {
|
||||
if (import.meta.env.VITE_ENABLE_PERF_LOG !== '1') {
|
||||
return fn();
|
||||
} else {
|
||||
return wrapFunctionCall(
|
||||
() => console.group(label),
|
||||
() => (console.groupEnd as (label: string) => void)(label),
|
||||
() => timedLogger(`${label}/total`, fn)
|
||||
() => timedLogger(`${label}/total`, fn),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ const dummyLogger = {
|
||||
};
|
||||
|
||||
export function getLogger() {
|
||||
if (import.meta.env.ENABLE_PERF_LOG === '1') {
|
||||
if (import.meta.env.VITE_ENABLE_PERF_LOG === '1') {
|
||||
return window.console;
|
||||
} else {
|
||||
return dummyLogger;
|
||||
|
||||
Reference in New Issue
Block a user