UNPKG

ids-enterprise-mcp-server

Version:

Model Context Protocol (MCP) server providing comprehensive IDS Enterprise Web Components documentation access via GitLab API. Use with npx and GitLab token for instant access.

137 lines 5.06 kB
/** * Development-focused logging utility for IDS Enterprise WC MCP Server */ export var LogLevel; (function (LogLevel) { LogLevel[LogLevel["ERROR"] = 0] = "ERROR"; LogLevel[LogLevel["WARN"] = 1] = "WARN"; LogLevel[LogLevel["INFO"] = 2] = "INFO"; LogLevel[LogLevel["DEBUG"] = 3] = "DEBUG"; LogLevel[LogLevel["TRACE"] = 4] = "TRACE"; })(LogLevel || (LogLevel = {})); // ANSI color codes for better visual distinction const colors = { reset: '\x1b[0m', red: '\x1b[31m', yellow: '\x1b[33m', blue: '\x1b[34m', green: '\x1b[32m', magenta: '\x1b[35m', cyan: '\x1b[36m', gray: '\x1b[90m', bold: '\x1b[1m' }; class Logger { level; startTime; constructor() { this.startTime = Date.now(); // Set log level based on environment const envLevel = process.env.IDS_LOG_LEVEL || process.env.NODE_ENV; switch (envLevel?.toLowerCase()) { case 'trace': this.level = LogLevel.TRACE; break; case 'debug': case 'development': this.level = LogLevel.DEBUG; break; case 'info': this.level = LogLevel.INFO; break; case 'warn': this.level = LogLevel.WARN; break; case 'error': case 'production': this.level = LogLevel.ERROR; break; default: // Default to DEBUG for development this.level = LogLevel.DEBUG; } // Show current log level on startup this.log(LogLevel.INFO, `${colors.cyan}[LOGGER]${colors.reset}`, `Log level: ${this.getLevelName()} (${this.level})`); } getLevelName() { return Object.keys(LogLevel)[Object.values(LogLevel).indexOf(this.level)] || 'UNKNOWN'; } getElapsedTime() { const elapsed = Date.now() - this.startTime; const seconds = (elapsed / 1000).toFixed(1); return `+${seconds}s`; } log(level, prefix, ...args) { if (level <= this.level) { const timestamp = new Date().toISOString().split('T')[1].split('.')[0]; // HH:MM:SS const elapsed = this.getElapsedTime(); console.log(`${colors.gray}${timestamp} ${elapsed}${colors.reset} ${prefix}`, ...args); } } error(...args) { this.log(LogLevel.ERROR, `${colors.red}${colors.bold}[ERROR]${colors.reset}`, ...args); } warn(...args) { this.log(LogLevel.WARN, `${colors.yellow}[WARN]${colors.reset}`, ...args); } info(...args) { this.log(LogLevel.INFO, `${colors.blue}[INFO]${colors.reset}`, ...args); } debug(...args) { this.log(LogLevel.DEBUG, `${colors.green}[DEBUG]${colors.reset}`, ...args); } trace(...args) { this.log(LogLevel.TRACE, `${colors.gray}[TRACE]${colors.reset}`, ...args); } // Specialized methods for development setup(...args) { this.log(LogLevel.INFO, `${colors.cyan}${colors.bold}[SETUP]${colors.reset}`, ...args); } api(...args) { this.log(LogLevel.DEBUG, `${colors.magenta}[API]${colors.reset}`, ...args); } component(...args) { this.log(LogLevel.TRACE, `${colors.yellow}[COMPONENT]${colors.reset}`, ...args); } performance(operation, startTime) { const duration = Date.now() - startTime; const color = duration > 5000 ? colors.red : duration > 2000 ? colors.yellow : colors.green; this.log(LogLevel.DEBUG, `${color}[PERF]${colors.reset}`, `${operation} took ${duration}ms`); } // Development helpers separator(title) { if (this.level >= LogLevel.DEBUG) { const line = '='.repeat(60); if (title) { console.log(`${colors.cyan}${line}${colors.reset}`); console.log(`${colors.cyan}${colors.bold} ${title} ${colors.reset}`); console.log(`${colors.cyan}${line}${colors.reset}`); } else { console.log(`${colors.gray}${line}${colors.reset}`); } } } progress(current, total, item) { if (this.level >= LogLevel.DEBUG) { const percent = Math.round((current / total) * 100); const bar = '█'.repeat(Math.floor(percent / 5)) + '░'.repeat(20 - Math.floor(percent / 5)); const itemText = item ? ` (${item})` : ''; console.log(`${colors.blue}[PROGRESS]${colors.reset} ${bar} ${percent}% (${current}/${total})${itemText}`); } } table(data) { if (this.level >= LogLevel.DEBUG) { console.log(`${colors.cyan}[TABLE]${colors.reset}`); console.table(data); } } json(label, data) { if (this.level >= LogLevel.TRACE) { console.log(`${colors.magenta}[JSON]${colors.reset} ${label}:`); console.log(JSON.stringify(data, null, 2)); } } } export const logger = new Logger(); //# sourceMappingURL=logger.js.map