UNPKG

claude-gemini-multimodal-bridge

Version:

Enterprise-grade AI integration bridge connecting Claude Code, Gemini CLI, and Google AI Studio with intelligent routing and advanced multimodal processing capabilities

156 lines (155 loc) 5.19 kB
import winston from 'winston'; class Logger { logger; static instance; static quietInstance; constructor(config) { const transports = []; if (config.console) { transports.push(new winston.transports.Console({ stderrLevels: [], format: config.json ? winston.format.json() : winston.format.combine(winston.format.colorize(), winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.printf(({ timestamp, level, message, ...meta }) => { const metaStr = Object.keys(meta).length ? JSON.stringify(meta, null, 2) : ''; return `${timestamp} [${level}]: ${message} ${metaStr}`; })), })); } if (config.file) { transports.push(new winston.transports.File({ filename: config.file, format: winston.format.combine(winston.format.timestamp(), winston.format.json()), })); } this.logger = winston.createLogger({ level: config.level, transports, defaultMeta: { service: 'cgmb' }, }); } static getInstance(config) { if (!Logger.instance) { const debugMode = process.env.CGMB_DEBUG === 'true'; const cliMode = process.env.CGMB_CLI_MODE === 'true'; const productionMode = process.env.NODE_ENV === 'production'; let logLevel = 'info'; if (debugMode) { logLevel = 'debug'; } else if (process.env.LOG_LEVEL) { logLevel = process.env.LOG_LEVEL; } else if (cliMode) { logLevel = 'warn'; } else if (productionMode) { logLevel = 'info'; } const defaultConfig = { level: logLevel, ...(process.env.LOG_FILE && { file: process.env.LOG_FILE }), console: !productionMode || debugMode, json: productionMode && !debugMode, }; Logger.instance = new Logger(config || defaultConfig); } return Logger.instance; } static getQuietInstance() { if (!Logger.quietInstance) { const quietConfig = { level: 'warn', console: true, json: false, }; Logger.quietInstance = new Logger(quietConfig); } return Logger.quietInstance; } static resetForCLI() { Logger.instance = null; Logger.quietInstance = null; process.env.LOG_LEVEL = 'warn'; } info(message, meta) { this.logger.info(message, meta); } error(message, error) { this.logger.error(message, error); } warn(message, meta) { this.logger.warn(message, meta); } debug(message, meta) { this.logger.debug(message, meta); } verbose(message, meta) { this.logger.verbose(message, meta); } layerOperation(layer, operation, duration, success, meta) { this.info(`Layer operation completed`, { layer, operation, duration, success, ...meta, }); } workflowStep(stepId, status, meta) { this.info(`Workflow step ${status}`, { stepId, status, ...meta, }); } apiCall(service, endpoint, duration, statusCode, meta) { this.debug(`API call to ${service}`, { service, endpoint, duration, statusCode, ...meta, }); } performance(operation, duration, meta) { this.info(`Performance metric`, { operation, duration, ...meta, }); } security(event, level, meta) { const logLevel = level === 'high' ? 'error' : level === 'medium' ? 'warn' : 'info'; this.logger.log(logLevel, `Security event: ${event}`, { securityLevel: level, ...meta, }); } debugConfig() { if (process.env.CGMB_DEBUG === 'true') { this.debug('CGMB Debug Configuration', { NODE_ENV: process.env.NODE_ENV, LOG_LEVEL: process.env.LOG_LEVEL, CGMB_DEBUG: process.env.CGMB_DEBUG, CGMB_CLI_MODE: process.env.CGMB_CLI_MODE, hasAiStudioKey: !!process.env.AI_STUDIO_API_KEY, hasGeminiKey: !!process.env.GEMINI_API_KEY, currentLogLevel: this.logger.level, }); } } static getDebugStatus() { return { debugMode: process.env.CGMB_DEBUG === 'true', cliMode: process.env.CGMB_CLI_MODE === 'true', logLevel: process.env.LOG_LEVEL, nodeEnv: process.env.NODE_ENV, hasDebugEnv: process.env.CGMB_DEBUG !== undefined, }; } } export const logger = process.env.CGMB_CLI_MODE === 'true' ? Logger.getQuietInstance() : Logger.getInstance(); export { Logger };