Download src/utils/logger.ts from agenthinkmesh/sane-assistant: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/utils/logger.ts
- Command line
-
hf download hf://agenthinkmesh/sane-assistant/src/utils/logger.ts
-
curl -L -o logger.ts https://huggingface.co/agenthinkmesh/sane-assistant/resolve/main/src/utils/logger.ts
1.55 kB
| import { config } from '../config'; | |
| type LogLevel = 'debug' | 'info' | 'warn' | 'error'; | |
| const levels: Record<LogLevel, number> = { | |
| debug: 0, | |
| info: 1, | |
| warn: 2, | |
| error: 3, | |
| }; | |
| const colors: Record<LogLevel, string> = { | |
| debug: '\x1b[36m', // cyan | |
| info: '\x1b[32m', // green | |
| warn: '\x1b[33m', // yellow | |
| error: '\x1b[31m', // red | |
| }; | |
| const reset = '\x1b[0m'; | |
| const bold = '\x1b[1m'; | |
| class Logger { | |
| private minLevel: number; | |
| constructor() { | |
| this.minLevel = levels[config.logLevel] ?? levels.info; | |
| } | |
| private log(level: LogLevel, module: string, message: string, data?: unknown): void { | |
| if (levels[level] < this.minLevel) return; | |
| const timestamp = new Date().toISOString(); | |
| const color = colors[level]; | |
| const levelStr = level.toUpperCase().padEnd(5); | |
| const moduleStr = `[${module}]`.padEnd(20); | |
| const line = `${color}${bold}${levelStr}${reset} ${timestamp} ${moduleStr} ${message}`; | |
| console.log(line); | |
| if (data !== undefined) { | |
| console.log(JSON.stringify(data, null, 2)); | |
| } | |
| } | |
| debug(module: string, message: string, data?: unknown): void { | |
| this.log('debug', module, message, data); | |
| } | |
| info(module: string, message: string, data?: unknown): void { | |
| this.log('info', module, message, data); | |
| } | |
| warn(module: string, message: string, data?: unknown): void { | |
| this.log('warn', module, message, data); | |
| } | |
| error(module: string, message: string, data?: unknown): void { | |
| this.log('error', module, message, data); | |
| } | |
| } | |
| export const logger = new Logger(); | |