import { Dispatch } from "./Dispatch"; import { ILogItem } from "./ILogItem"; import { LogLevel } from "./LogLevel"; export class FormattedDispatch extends Dispatch { private formatString: string = "%t %l <%o>: %m"; format(item: ILogItem): string { return this.formatString .replace("%t", item.timestamp.toISOString()) .replace("%l", LogLevel[item.level]) .replace("%o", item.origin || "") .replace( "%m", item.data .map((item: any) => { switch (typeof item) { case "string": case "number": return item; case "object": return JSON.stringify(item); default: return item; } }) .join(" "), ); } process(item: ILogItem): void { super.process({ ...item, data: this.format(item), }); } }