@simonecoelhosfo/optimizely-mcp-server
Version:
Optimizely MCP Server for AI assistants with integrated CLI tools
214 lines • 6.65 kB
TypeScript
/**
* Pino-based logging infrastructure for Optimizely MCP Server
* @description Provides file-based logging that is safe for StdioServerTransport
*
* CRITICAL: This logging system is designed to prevent stdout contamination
* which would break MCP StdioServerTransport communication.
*
* @author Optimizely MCP Server
* @version 1.0.0
*/
/**
* Configuration interface for the logging system
* @description Defines all configurable aspects of the logging infrastructure
*/
export interface LoggerConfig {
/** File path for log output */
logFile?: string;
/** Log level (trace, debug, info, warn, error, fatal) */
logLevel?: string;
/** Enable console logging to stderr (safe for debugging) */
consoleLogging?: boolean;
/** Enable pretty printing for development */
prettyPrint?: boolean;
/** Maximum log file size before rotation */
maxFileSize?: number;
/** Number of rotated log files to keep */
maxFiles?: number;
}
/**
* Optimizely MCP Server Logger
* @description Thread-safe, async logging system designed for MCP server usage
*
* Key Features:
* - File-based logging (safe for StdioServerTransport)
* - Configurable via environment variables
* - Automatic directory creation
* - Fallback to temp directory if primary path fails
* - Structured JSON logging for production
* - Optional stderr logging for development
*
* Environment Variables:
* - OPTIMIZELY_MCP_LOG_FILE: Log file path
* - OPTIMIZELY_MCP_LOG_LEVEL: Log level (trace|debug|info|warn|error|fatal)
* - OPTIMIZELY_MCP_CONSOLE_LOGGING: Enable stderr logging (true|false)
*
* @example
* ```typescript
* import { createLogger } from './logging/Logger.js';
*
* const logger = createLogger();
* logger.info('Server started successfully');
* logger.error('Failed to connect to API', { error: 'Connection timeout' });
* ```
*/
export declare class OptimizelyMCPLogger {
private logger;
private config;
/**
* Creates a new OptimizelyMCPLogger instance
* @param config - Logger configuration options
* @throws {Error} When logger initialization fails
*/
constructor(config?: LoggerConfig);
/**
* Merges user configuration with defaults and environment variables
* @param userConfig - User-provided configuration
* @returns Complete configuration with all required fields
* @private
*/
private mergeConfig;
/**
* Initializes the Pino logger with appropriate transports
* @returns Configured Pino logger instance
* @throws {Error} When logger setup fails
* @private
*/
private initializeLogger;
/**
* Ensures the log directory exists and returns a valid log file path
* @param logFilePath - Desired log file path
* @returns Validated log file path
* @throws {Error} When directory creation fails
* @private
*/
private ensureLogDirectory;
/**
* Archives existing log file if it exceeds the max size
* @param logFile - Path to the log file
* @private
*/
private archiveExistingLargeLog;
/**
* Logs a trace level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
trace(obj: any, msg?: string): void;
/**
* Logs a debug level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
debug(obj: any, msg?: string): void;
/**
* Logs an info level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
info(obj: any, msg?: string): void;
/**
* Logs a warning level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
warn(obj: any, msg?: string): void;
/**
* Logs an error level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
error(obj: any, msg?: string): void;
/**
* Logs a fatal level message
* @param obj - Object or message to log
* @param msg - Optional message string
*/
fatal(obj: any, msg?: string): void;
/**
* Creates a child logger with additional context
* @param bindings - Additional context to include in all log messages
* @returns Child logger instance
*/
child(bindings: object): OptimizelyMCPLogger;
/**
* Flushes any pending log messages
* @description Ensures all log messages are written before process exit
* @returns Promise that resolves when flush is complete
*/
flush(): Promise<void>;
/**
* Gets the current log level
* @returns Current log level string
*/
getLevel(): string;
/**
* Sets the log level dynamically
* @param level - New log level to set
*/
setLevel(level: string): void;
/**
* Gets the current log file path
* @returns Current log file path
*/
getLogFile(): string;
}
/**
* Creates and configures the global logger instance
* @param config - Optional logger configuration
* @returns Configured logger instance
*
* @example
* ```typescript
* import { createLogger } from './logging/Logger.js';
*
* const logger = createLogger({
* logLevel: 'debug',
* consoleLogging: true
* });
* ```
*/
export declare function createLogger(config?: LoggerConfig): OptimizelyMCPLogger;
/**
* Gets the global logger instance
* @returns Global logger instance (creates one if none exists)
*
* @example
* ```typescript
* import { getLogger } from './logging/Logger.js';
*
* const logger = getLogger();
* logger.info('Application started');
* ```
*/
export declare function getLogger(): OptimizelyMCPLogger;
/**
* Flushes all pending log messages and closes the logger
* @description Should be called before process exit to ensure all logs are written
* @returns Promise that resolves when shutdown is complete
*
* @example
* ```typescript
* import { shutdownLogger } from './logging/Logger.js';
*
* process.on('SIGTERM', async () => {
* await shutdownLogger();
* process.exit(0);
* });
* ```
*/
export declare function shutdownLogger(): Promise<void>;
/**
* Safe stderr logging function for emergency use
* @description When all else fails, this provides a way to log to stderr
* @param message - Message to log to stderr
*
* @example
* ```typescript
* import { emergencyLog } from './logging/Logger.js';
*
* emergencyLog('Critical system failure - using emergency logging');
* ```
*/
export declare function emergencyLog(message: string): void;
//# sourceMappingURL=Logger.d.ts.map