/** * Logger utility for VC-SYS CLI */ import chalk from 'chalk'; export enum LogLevel { DEBUG = 0, INFO = 1, WARN = 2, ERROR = 3 } export class Logger { private context: string; private level: LogLevel; constructor(context: string, level: LogLevel = LogLevel.INFO) { this.context = context; this.level = level; } debug(message: string, data?: any): void { if (this.level <= LogLevel.DEBUG) { const timestamp = new Date().toISOString(); console.log(chalk.gray(`[${timestamp}] [DEBUG] [${this.context}] ${message}`)); if (data) { console.log(chalk.gray(JSON.stringify(data, null, 2))); } } } info(message: string, data?: any): void { if (this.level <= LogLevel.INFO) { const timestamp = new Date().toISOString(); console.log(chalk.blue(`[${timestamp}] [INFO] [${this.context}] ${message}`)); if (data) { console.log(chalk.gray(JSON.stringify(data, null, 2))); } } } warn(message: string, data?: any): void { if (this.level <= LogLevel.WARN) { const timestamp = new Date().toISOString(); console.warn(chalk.yellow(`[${timestamp}] [WARN] [${this.context}] ${message}`)); if (data) { console.warn(chalk.gray(JSON.stringify(data, null, 2))); } } } error(message: string, error?: any): void { if (this.level <= LogLevel.ERROR) { const timestamp = new Date().toISOString(); console.error(chalk.red(`[${timestamp}] [ERROR] [${this.context}] ${message}`)); if (error) { if (error instanceof Error) { console.error(chalk.red(error.stack)); } else { console.error(chalk.red(JSON.stringify(error, null, 2))); } } } } setLevel(level: LogLevel): void { this.level = level; } }