UNPKG

openapi-directory-mcp

Version:

Model Context Protocol server for accessing enhanced triple-source OpenAPI directory (APIs.guru + additional APIs + custom imports)

89 lines 2.98 kB
/** * Simple logger utility for consistent logging across the application * Uses debug levels to control output in different environments */ var _a; 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 = {})); export class Logger { static getLogLevelFromEnv() { const level = process.env.LOG_LEVEL?.toUpperCase(); switch (level) { case "ERROR": return LogLevel.ERROR; case "WARN": return LogLevel.WARN; case "INFO": return LogLevel.INFO; case "DEBUG": return LogLevel.DEBUG; default: // Default to WARN in production, DEBUG in development/test return process.env.NODE_ENV === "production" ? LogLevel.WARN : LogLevel.DEBUG; } } static error(message, ...args) { if (this.logLevel >= LogLevel.ERROR) { // eslint-disable-next-line no-console console.error(`[ERROR] ${message}`, ...args); } } static warn(message, ...args) { if (this.logLevel >= LogLevel.WARN) { // eslint-disable-next-line no-console console.warn(`[WARN] ${message}`, ...args); } } static info(message, ...args) { if (this.logLevel >= LogLevel.INFO) { // eslint-disable-next-line no-console console.info(`[INFO] ${message}`, ...args); } } static debug(message, ...args) { if (this.logLevel >= LogLevel.DEBUG) { // eslint-disable-next-line no-console console.log(`[DEBUG] ${message}`, ...args); } } /** * Special method for cache operations - uses debug level * to avoid cluttering production logs */ static cache(operation, key, details) { if (this.logLevel >= LogLevel.DEBUG) { const sanitizedKey = key ? this.sanitizeKey(key) : ""; const message = details ? `[CACHE] ${operation}: ${sanitizedKey} - ${JSON.stringify(details)}` : `[CACHE] ${operation}: ${sanitizedKey}`; // eslint-disable-next-line no-console console.log(message); } } /** * Sanitize cache keys to avoid exposing sensitive information */ static sanitizeKey(key) { // Truncate long keys and mask potentially sensitive parts if (key.length > 50) { return `${key.substring(0, 20)}...${key.substring(key.length - 20)}`; } return key; } /** * Set log level dynamically */ static setLogLevel(level) { this.logLevel = level; } } _a = Logger; Logger.logLevel = _a.getLogLevelFromEnv(); //# sourceMappingURL=logger.js.map