import * as fs from "fs"; import { FormattedDispatch } from "./FormattedDispatch"; import { App } from "../App"; import { ILogItem } from "./ILogItem"; export class FileDispatch extends FormattedDispatch { path: string; stream: fs.WriteStream; constructor(path: string) { super(); this.path = path; this.stream = fs.createWriteStream(path, { flags: "a" }); this.stream.on("error", (err) => { App.logger.error(`Error writing to file: ${this.path}`, err); }); } process(item: ILogItem): void { this.stream.write(this.format(item) + "\n"); super.process(item); } }