From 9bf7fa43028e9a65b4f55ec2d9420997d2c8ba65 Mon Sep 17 00:00:00 2001 From: Strix Date: Wed, 5 Feb 2025 12:37:06 +0100 Subject: [PATCH] fix: use new format --- FileDispatch.ts | 6 ++---- FormattedDispatch.ts | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FileDispatch.ts b/FileDispatch.ts index e4f009a..3624d93 100644 --- a/FileDispatch.ts +++ b/FileDispatch.ts @@ -12,12 +12,10 @@ export class FileDispatch extends FormattedDispatch { 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); + output(item: ILogItem): void { + this.stream.write(item.data + "\n"); } } diff --git a/FormattedDispatch.ts b/FormattedDispatch.ts index 95cc0d4..0fbafa5 100644 --- a/FormattedDispatch.ts +++ b/FormattedDispatch.ts @@ -13,7 +13,7 @@ export class FormattedDispatch extends Dispatch { case "number": return x; case "object": - return JSON.stringify(x); + return JSON.stringify(x, null, 2); default: return x; } @@ -40,7 +40,9 @@ export class FormattedDispatch extends Dispatch { } process(item: ILogItem): void { - if (item.flags?.includes("skip_formatting")) return super.process(item); + if (item.flags?.includes("formatting:none")) return super.process(item); + else if (item.flags?.includes("formatting:json_string")) return super.process({...item, data: JSON.stringify(item.data)}); + else if (item.flags?.includes("formatting:pretty_json_string")) return super.process({...item, data: JSON.stringify(item.data, null, 2)}); super.process({ ...item, data: this.format(item),