Create logfile if it doesnt exist

This commit is contained in:
Jesse Wierzbinski 2024-04-06 17:50:32 -10:00
parent 53cd73262c
commit 6b2e4044b6
No known key found for this signature in database

View file

@ -42,10 +42,13 @@ export class LogManager {
if (this.output == Bun.stdout) { if (this.output == Bun.stdout) {
await Bun.write(Bun.stdout, text + "\n"); await Bun.write(Bun.stdout, text + "\n");
} else { } else {
if (!this.output.name) { if (!(await this.output.exists())) {
throw new Error(`Output file doesnt exist (and isnt stdout)`); // 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");
} }
} }