logger.ts•945 B
type LogLevel = 'debug' | 'info' | 'warn' | 'error';
const LOG_LEVELS: Record<LogLevel, number> = {
debug: 0,
info: 1,
warn: 2,
error: 3
};
export class Logger {
private level: LogLevel = 'info';
setLevel(level: LogLevel) {
this.level = level;
}
private shouldLog(level: LogLevel): boolean {
return LOG_LEVELS[level] >= LOG_LEVELS[this.level];
}
debug(...args: any[]) {
if (this.shouldLog('debug')) {
console.log('[MCP LS Debug]', ...args);
}
}
info(...args: any[]) {
if (this.shouldLog('info')) {
console.log('[MCP LS Info]', ...args);
}
}
warn(...args: any[]) {
if (this.shouldLog('warn')) {
console.warn('[MCP LS Warn]', ...args);
}
}
error(...args: any[]) {
if (this.shouldLog('error')) {
console.error('[MCP LS Error]', ...args);
}
}
}