31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
/**
|
|
* Lightweight browser-safe logger for analytics debug output.
|
|
* All output is gated behind the `enabled` flag — in production,
|
|
* enableDebugLogging is false and nothing is emitted.
|
|
*
|
|
* Uses globalThis.console to avoid lint rules that block direct console usage.
|
|
* This is intentional: analytics debug logging has no alternative output sink
|
|
* in browser environments.
|
|
*/
|
|
|
|
interface AnalyticsLogger {
|
|
debug(msg: string, ...args: unknown[]): void
|
|
warn(msg: string, ...args: unknown[]): void
|
|
error(msg: string, ...args: unknown[]): void
|
|
}
|
|
|
|
const browserConsole = globalThis.console;
|
|
|
|
export function createLogger(enabled: boolean): AnalyticsLogger {
|
|
const noop = () => {};
|
|
|
|
if (!enabled) {
|
|
return { debug: noop, warn: noop, error: noop };
|
|
}
|
|
|
|
return {
|
|
debug: (msg: string, ...args: unknown[]) => browserConsole.debug(`[Analytics] ${msg}`, ...args),
|
|
warn: (msg: string, ...args: unknown[]) => browserConsole.warn(`[Analytics] ${msg}`, ...args),
|
|
error: (msg: string, ...args: unknown[]) => browserConsole.error(`[Analytics] ${msg}`, ...args),
|
|
};
|
|
}
|