import * as fs from "fs"; import { FormattedDispatch } from "./FormattedDispatch"; import { App } from "../App"; import { ILogItem } from "./ILogItem"; import { LOGE, LOGW } from "./common"; 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) => LOGE(`Error writing to file: ${this.path}`, err)); } process(item: ILogItem): void { this.stream.write(this.format(item) + "\n"); super.process(item); } }