mirror of
https://git.unlock-music.dev/um/um-react.git
synced 2024-11-23 20:02:16 +00:00
fix: performance logging code
This commit is contained in:
parent
985620d188
commit
bb9529b877
2
.env
2
.env
@ -1,4 +1,4 @@
|
|||||||
# Example environment file for vite to use.
|
# Example environment file for vite to use.
|
||||||
# For more information, see: https://vitejs.dev/guide/env-and-mode.html
|
# For more information, see: https://vitejs.dev/guide/env-and-mode.html
|
||||||
|
|
||||||
ENABLE_PERF_LOG=0
|
VITE_ENABLE_PERF_LOG=0
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
import { wrapFunctionCall } from './fnWrapper';
|
import { wrapFunctionCall } from './fnWrapper';
|
||||||
|
|
||||||
export function timedLogger<R = unknown>(label: string, fn: () => R): R {
|
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();
|
return fn();
|
||||||
} else {
|
} else {
|
||||||
return wrapFunctionCall(
|
return wrapFunctionCall(
|
||||||
() => console.time(label),
|
() => console.time(label),
|
||||||
() => console.timeEnd(label),
|
() => console.timeEnd(label),
|
||||||
fn
|
fn,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function withGroupedLogs<R = unknown>(label: string, fn: () => R): R {
|
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();
|
return fn();
|
||||||
} else {
|
} else {
|
||||||
return wrapFunctionCall(
|
return wrapFunctionCall(
|
||||||
() => console.group(label),
|
() => console.group(label),
|
||||||
() => (console.groupEnd as (label: string) => void)(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() {
|
export function getLogger() {
|
||||||
if (import.meta.env.ENABLE_PERF_LOG === '1') {
|
if (import.meta.env.VITE_ENABLE_PERF_LOG === '1') {
|
||||||
return window.console;
|
return window.console;
|
||||||
} else {
|
} else {
|
||||||
return dummyLogger;
|
return dummyLogger;
|
||||||
|
Loading…
Reference in New Issue
Block a user