// Copyright 2025 Chris Bunting
// Brief: Logger utility for Code Complexity Analyzer MCP Server
// Scope: Provides logging functionality with different log levels
export class Logger {
private logLevel: string;
constructor(logLevel: string = 'info') {
this.logLevel = logLevel;
}
private shouldLog(level: string): boolean {
const levels = ['debug', 'info', 'warn', 'error'];
const currentLevelIndex = levels.indexOf(this.logLevel);
const messageLevelIndex = levels.indexOf(level);
return messageLevelIndex >= currentLevelIndex;
}
private formatMessage(level: string, message: string, ...args: any[]): string {
const timestamp = new Date().toISOString();
const formattedArgs = args.length > 0 ? ` ${args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
).join(' ')}` : '';
return `[${timestamp}] ${level.toUpperCase()}: ${message}${formattedArgs}`;
}
debug(message: string, ...args: any[]): void {
if (this.shouldLog('debug')) {
console.log(this.formatMessage('debug', message, ...args));
}
}
info(message: string, ...args: any[]): void {
if (this.shouldLog('info')) {
console.log(this.formatMessage('info', message, ...args));
}
}
warn(message: string, ...args: any[]): void {
if (this.shouldLog('warn')) {
console.warn(this.formatMessage('warn', message, ...args));
}
}
error(message: string, ...args: any[]): void {
if (this.shouldLog('error')) {
console.error(this.formatMessage('error', message, ...args));
}
}
}