From e808a4f414b890bf1a1055bb9dcc79dd46ad463a Mon Sep 17 00:00:00 2001 From: Kallum Jones Date: Thu, 4 Aug 2022 16:15:19 +0100 Subject: [PATCH] Cleanup blank log files --- src/mod-manager.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/mod-manager.ts b/src/mod-manager.ts index 7601565..e8b5fd7 100644 --- a/src/mod-manager.ts +++ b/src/mod-manager.ts @@ -10,6 +10,7 @@ import {Logger, pino} from "pino" import {ListCommand} from "./commands/list_command.js"; import UninstallCommand from "./commands/uninstall_command.js"; import EssentialCommand from "./commands/essential_command.js"; +import {readFileSync, unlinkSync} from "fs"; export default class ModManager { @@ -57,6 +58,14 @@ export default class ModManager { setTimeout(() => process.exit(1), 1) }) + // If no errors are logged, cleanup the log file when the process exits + process.on("exit", () => { + // If file is only whitespace, i.e. blank + if (!readFileSync(this.LOG_FILE, "utf-8").trim().length) { + unlinkSync(this.LOG_FILE) + } + }) + return logger; } }