feat: add log-level system to suppress noisy fallback debug output

Replace console.debug/log/warn calls in model router, retry, and daemon
startup with a structured logger that respects a configurable log_level.
Default level is 'info', suppressing verbose fallback debug messages in
the TUI while keeping them available via config when needed.

- Add src/logger.ts with debug/info/warn/error/silent levels
- Wire log_level into config schema (default: 'info')
- Initialize log level in both daemon and TUI startup paths
- Convert all console.debug in router.ts and retry.ts to logger.debug
- Convert console.log/warn in daemon/models.ts to logger.info/warn
This commit is contained in:
William Valentin
2026-02-09 21:23:07 -08:00
parent 94946eb7a8
commit 35f4cab0dc
8 changed files with 79 additions and 16 deletions
+44
View File
@@ -0,0 +1,44 @@
/** 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);
},
};