import { statSync } from "node:fs"; import { IDispatch, IDispatchConfig } from "./IDispatch"; import { ILogItem } from "./ILogItem"; import { LogLevel } from "./LogLevel"; export class Dispatch implements IDispatch { private dispatches: IDispatch[] = []; constructor(config: IDispatchConfig = {}) {} trace(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Trace, data: args }); } debug(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Debug, data: args }); } info(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Info, data: args }); } warn(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Warn, data: args }); } error(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Error, data: args }); } fatal(...args: any[]): void { this.process({ timestamp: new Date(), level: LogLevel.Fatal, data: args }); } process(item: ILogItem): void { for (const dispatch of this.dispatches) { dispatch.process(item); } } add(dispatch: IDispatch): Dispatch { this.dispatches.push(dispatch); return this; } }