/**
* Simple logging utility with configurable levels
*/
import { config } from './config.js';
type LogLevel = 'error' | 'warn' | 'info' | 'debug';
const LEVELS: Record<LogLevel, number> = {
error: 0,
warn: 1,
info: 2,
debug: 3,
};
class Logger {
private level: number;
constructor() {
this.level = LEVELS[config.logLevel];
}
private shouldLog(level: LogLevel): boolean {
return LEVELS[level] <= this.level;
}
error(message: string, ...args: unknown[]): void {
if (this.shouldLog('error')) {
console.error(`[ERROR] ${message}`, ...args);
}
}
warn(message: string, ...args: unknown[]): void {
if (this.shouldLog('warn')) {
console.warn(`[WARN] ${message}`, ...args);
}
}
info(message: string, ...args: unknown[]): void {
if (this.shouldLog('info')) {
console.info(`[INFO] ${message}`, ...args);
}
}
debug(message: string, ...args: unknown[]): void {
if (this.shouldLog('debug')) {
console.debug(`[DEBUG] ${message}`, ...args);
}
}
}
export const logger = new Logger();