mirror of
https://github.com/SableClient/Sable.git
synced 2026-11-27 12:26:29 -08:00
27 lines
885 B
TypeScript
27 lines
885 B
TypeScript
/**
|
|
* Lightweight debug logger for the account switcher (and other features).
|
|
*
|
|
* Enable in the browser console:
|
|
* localStorage.setItem('sable_debug', '1'); location.reload();
|
|
*
|
|
* Disable:
|
|
* localStorage.removeItem('sable_debug'); location.reload();
|
|
*/
|
|
|
|
const isDebug = (): boolean => localStorage.getItem('sable_debug') === '1';
|
|
|
|
type LogLevel = 'log' | 'warn' | 'error';
|
|
|
|
const fmt = (namespace: string, level: LogLevel, ...args: unknown[]): void => {
|
|
if (!isDebug() && level === 'log') return;
|
|
const prefix = `[sable:${namespace}]`;
|
|
// eslint-disable-next-line no-console
|
|
console[level](prefix, ...args);
|
|
};
|
|
|
|
export const createLogger = (namespace: string) => ({
|
|
log: (...args: unknown[]) => fmt(namespace, 'log', ...args),
|
|
warn: (...args: unknown[]) => fmt(namespace, 'warn', ...args),
|
|
error: (...args: unknown[]) => fmt(namespace, 'error', ...args),
|
|
});
|