mcp-adr-analysis-server
Version:
MCP server for analyzing Architectural Decision Records and project architecture
195 lines • 6.11 kB
TypeScript
/**
* Enhanced Logging System
*
* Provides comprehensive logging with structured error reporting,
* diagnostic context, and actionable error messages.
*/
import { EnhancedError, DiagnosticContext } from '../types/enhanced-errors.js';
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'critical';
export interface LogEntry {
timestamp: Date;
level: LogLevel;
message: string;
component: string;
operation?: string;
context?: Record<string, any>;
error?: any;
diagnostics?: DiagnosticContext;
performanceMetrics?: {
memoryUsage?: number;
cpuUsage?: number;
duration?: number;
queueSize?: number;
activeOperations?: number;
};
}
export interface LoggerConfig {
level: LogLevel;
enableConsole: boolean;
enableFile: boolean;
filePath?: string;
maxFileSize?: number;
maxFiles?: number;
enableStructuredLogging: boolean;
enablePerformanceMetrics: boolean;
}
/**
* Enhanced Logger with comprehensive error reporting and diagnostics
*/
export declare class EnhancedLogger {
private config;
private logBuffer;
private maxBufferSize;
constructor(config?: Partial<LoggerConfig>);
/**
* Log debug information
*/
debug(message: string, component: string, context?: Record<string, any>): void;
/**
* Log informational messages
*/
info(message: string, component: string, context?: Record<string, any>): void;
/**
* Log warning messages
*/
warn(message: string, component: string, context?: Record<string, any>): void;
/**
* Log error messages
*/
error(message: string, component: string, error?: Error, context?: Record<string, any>): void;
/**
* Log critical errors
*/
critical(message: string, component: string, error?: Error, context?: Record<string, any>): void;
/**
* Log enhanced errors with full diagnostic information
*/
logEnhancedError(error: EnhancedError): void;
/**
* Log operation start with performance tracking
*/
logOperationStart(operation: string, component: string, context?: Record<string, any>): string;
/**
* Log operation completion with performance metrics
*/
logOperationComplete(operationId: string, operation: string, component: string, duration: number, context?: Record<string, any>): void;
/**
* Log operation failure with recovery suggestions
*/
logOperationFailure(operationId: string, operation: string, component: string, error: Error, duration: number, context?: Record<string, any>): void;
/**
* Log performance metrics
*/
logPerformanceMetrics(component: string, operation: string, metrics: {
memoryUsage?: number;
cpuUsage?: number;
duration?: number;
queueSize?: number;
activeOperations?: number;
throughput?: number;
}): void;
/**
* Get recent log entries for debugging
*/
getRecentLogs(count?: number): LogEntry[];
/**
* Get logs filtered by level and component
*/
getFilteredLogs(filters: {
level?: LogLevel;
component?: string;
operation?: string;
since?: Date;
}): LogEntry[];
/**
* Clear log buffer
*/
clearLogs(): void;
/**
* Core logging method
*/
private log;
/**
* Write log entry to configured outputs
*/
private writeLogEntry;
/**
* Write to console with appropriate formatting
*/
private writeToConsole;
/**
* Write to file (placeholder - would need file system implementation)
*/
private writeToFile;
/**
* Check if log level is enabled
*/
private isLevelEnabled;
/**
* Check if a specific level meets the filter criteria
*/
private levelMeetsFilter;
/**
* Map error severity to log level
*/
private mapSeverityToLogLevel;
/**
* Serialize error for logging
*/
private serializeError;
/**
* Get current memory usage
*/
private getMemoryUsage;
/**
* Generate unique operation ID
*/
private generateOperationId;
}
/**
* Global logger instance
*/
export declare const logger: EnhancedLogger;
/**
* Create component-specific logger
*/
export declare function createComponentLogger(component: string, config?: Partial<LoggerConfig>): ComponentLogger;
/**
* Component-specific logger wrapper
*/
export declare class ComponentLogger {
private logger;
private component;
constructor(component: string, config?: Partial<LoggerConfig>);
debug(message: string, context?: Record<string, any>): void;
info(message: string, context?: Record<string, any>): void;
warn(message: string, context?: Record<string, any>): void;
error(message: string, error?: Error, context?: Record<string, any>): void;
critical(message: string, error?: Error, context?: Record<string, any>): void;
logEnhancedError(error: EnhancedError): void;
logOperationStart(operation: string, context?: Record<string, any>): string;
logOperationComplete(operationId: string, operation: string, duration: number, context?: Record<string, any>): void;
logOperationFailure(operationId: string, operation: string, error: Error, duration: number, context?: Record<string, any>): void;
logPerformanceMetrics(operation: string, metrics: Record<string, any>): void;
}
/**
* Error recovery utilities
*/
export declare class ErrorRecoveryManager {
private logger;
private recoveryStrategies;
constructor(logger?: EnhancedLogger);
/**
* Register recovery strategy for specific error codes
*/
registerRecoveryStrategy(errorCode: string, strategy: (error: EnhancedError) => Promise<boolean>): void;
/**
* Attempt to recover from an enhanced error
*/
attemptRecovery(error: EnhancedError): Promise<boolean>;
/**
* Get recovery suggestions for an error
*/
getRecoverySuggestions(error: EnhancedError): string[];
}
//# sourceMappingURL=enhanced-logging.d.ts.map