/** * Simple structured logger for the bridge process. * Outputs JSON lines to stdout for Python to capture. */ export enum LogLevel { DEBUG = 'DEBUG', INFO = 'INFO', WARN = 'WARN', ERROR = 'ERROR', } let currentLevel = LogLevel.INFO; export function setLogLevel(level: LogLevel): void { currentLevel = level; } const levelPriority: Record = { [LogLevel.DEBUG]: 0, [LogLevel.INFO]: 1, [LogLevel.WARN]: 2, [LogLevel.ERROR]: 3, }; function log(level: LogLevel, module: string, message: string, data?: any): void { if (levelPriority[level] < levelPriority[currentLevel]) return; const entry = { timestamp: new Date().toISOString(), level, module, message, ...(data !== undefined ? { data } : {}), }; // Output as JSON line for Python to parse console.log(JSON.stringify(entry)); } export function createLogger(module: string) { return { debug: (msg: string, data?: any) => log(LogLevel.DEBUG, module, msg, data), info: (msg: string, data?: any) => log(LogLevel.INFO, module, msg, data), warn: (msg: string, data?: any) => log(LogLevel.WARN, module, msg, data), error: (msg: string, data?: any) => log(LogLevel.ERROR, module, msg, data), }; }