Files
flynn/src/logger.ts
T
William Valentin 6090508bad style: auto-fix ESLint issues (curly braces and formatting)
- Add curly braces to all if/else/for/while statements
- Fix indentation and trailing spaces
- Auto-fixed 372 linting errors using eslint --fix
- Remaining issues are warnings only (non-null assertions, explicit any types)
2026-02-11 10:30:24 -08:00

45 lines
1.0 KiB
TypeScript

/** Simple log-level utility.
*
* Default level is `info`, which suppresses `debug` output.
* Set to `debug` (via config or `setLevel()`) to see all messages.
*/
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'silent';
const LEVELS: Record<LogLevel, number> = {
debug: 0,
info: 1,
warn: 2,
error: 3,
silent: 4,
};
let currentLevel: LogLevel = 'info';
export function setLogLevel(level: LogLevel): void {
currentLevel = level;
}
export function getLogLevel(): LogLevel {
return currentLevel;
}
function shouldLog(level: LogLevel): boolean {
return LEVELS[level] >= LEVELS[currentLevel];
}
export const logger = {
debug(...args: unknown[]): void {
if (shouldLog('debug')) {console.debug(...args);}
},
info(...args: unknown[]): void {
if (shouldLog('info')) {console.log(...args);}
},
warn(...args: unknown[]): void {
if (shouldLog('warn')) {console.warn(...args);}
},
error(...args: unknown[]): void {
if (shouldLog('error')) {console.error(...args);}
},
};