export interface TracingLogger { info(log: string): void; warn(log: string): void; error(log: string): void; debug(log: string): void; createChild(prefix: string): TracingLogger; } export type LogLevel = 'debug' | 'info' | 'warn' | 'error'; export class ConsoleTracingLogger implements TracingLogger { protected prefix: string; private levels: LogLevel[]; constructor(prefix: string, levels: LogLevel[] = ['warn', 'error']) { this.prefix = prefix; this.levels = levels; } private makePrefix(level: LogLevel): string { return `[${new Date().toISOString()}] ${level} (${this.prefix}) > `; } public info(log: string) { if (this.levels.includes('info')) console.log(this.makePrefix('info') + log); } public warn(log: string) { if (this.levels.includes('warn')) console.warn(this.makePrefix('warn') + log); } public error(log: string) { if (this.levels.includes('error')) console.error(this.makePrefix('error') + log); } public debug(log: string) { if (this.levels.includes('debug')) console.debug(this.makePrefix('debug') + log); } public createChild(prefix: string, levels?: LogLevel[]) { return new ConsoleTracingLogger( `${this.prefix} -> ${prefix}`, levels ?? this.levels, ); } }