UNPKG

@thorium-dev-group/x402-mcp-extension

Version:
94 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConsoleLogger = void 0; const DEFAULT_CONFIG = { showTimestamp: true, showLevel: true, showComponent: true, }; class ConsoleLogger { config; component; level; constructor(component, level, config = {}) { this.component = component; this.level = level; this.config = { ...DEFAULT_CONFIG, ...config, }; } shouldLog(messageLevel) { const levels = { error: 0, warn: 1, info: 2, debug: 3, }; return levels[messageLevel] <= levels[this.level]; } formatMessage(level, message, args) { const parts = []; if (this.config.showTimestamp) { parts.push(new Date().toISOString().substring(11, 19)); } if (this.config.showLevel) { parts.push(`[${level.toUpperCase()}]`); } if (this.config.showComponent) { parts.push(this.component); } if (this.config.extra) { parts.push(JSON.stringify(this.config.extra)); } parts.push(message); if (args.length > 0) { const formattedArgs = args.map(arg => { if (arg instanceof Error) { return `${arg.message}\n${arg.stack}`; } else if (typeof arg === 'object' && arg !== null) { return JSON.stringify(arg); } else { return String(arg); } }).join(' '); if (formattedArgs) { parts.push(`(${formattedArgs})`); } } return parts.join(' '); } log(level, message, args) { if (!this.shouldLog(level)) return; const formattedMessage = this.formatMessage(level, message, args); switch (level) { case 'error': console.error(formattedMessage); break; case 'warn': console.warn(formattedMessage); break; case 'info': case 'debug': console.log(formattedMessage); break; } } error(message, ...args) { this.log('error', message, args); } warn(message, ...args) { this.log('warn', message, args); } info(message, ...args) { this.log('info', message, args); } debug(message, ...args) { this.log('debug', message, args); } } exports.ConsoleLogger = ConsoleLogger; //# sourceMappingURL=ConsoleLogger.js.map