import * as fs from 'fs';
import * as path from 'path';
/**
* Simple file-based logger
*/
export class Logger {
private static logFile = path.resolve(process.cwd(), 'ask-me-mcp.log');
private static write(level: string, message: string, ...args: any[]) {
const timestamp = new Date().toISOString();
const formattedArgs = args.map(arg =>
typeof arg === 'object' ? JSON.stringify(arg) : String(arg)
).join(' ');
const logEntry = `[${timestamp}] [${level}] ${message} ${formattedArgs}\n`;
// Write to file synchronously to ensure logs are captured even if crash occurs
try {
fs.appendFileSync(this.logFile, logEntry);
} catch (e) {
// Fallback to console if file write fails
console.error('Failed to write to log file:', e);
}
}
static info(message: string, ...args: any[]) {
this.write('INFO', message, ...args);
}
static error(message: string, ...args: any[]) {
this.write('ERROR', message, ...args);
}
static debug(message: string, ...args: any[]) {
this.write('DEBUG', message, ...args);
}
static log(message: string, ...args: any[]) {
this.write('LOG', message, ...args);
}
}