From 6b2e4044b6deb454ae786566e450753abf878bfe Mon Sep 17 00:00:00 2001 From: Jesse Wierzbinski Date: Sat, 6 Apr 2024 17:50:32 -1000 Subject: [PATCH] Create logfile if it doesnt exist --- packages/log-manager/index.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/log-manager/index.ts b/packages/log-manager/index.ts index 37d03e1d..11d34196 100644 --- a/packages/log-manager/index.ts +++ b/packages/log-manager/index.ts @@ -42,10 +42,13 @@ export class LogManager { if (this.output == Bun.stdout) { await Bun.write(Bun.stdout, text + "\n"); } else { - if (!this.output.name) { - throw new Error(`Output file doesnt exist (and isnt stdout)`); + if (!(await this.output.exists())) { + // Create file if it doesn't exist + await Bun.write(this.output, "", { + createPath: true, + }); } - await appendFile(this.output.name, text + "\n"); + await appendFile(this.output.name ?? "", text + "\n"); } }