Cleanup blank log files

This commit is contained in:
Kallum Jones 2022-08-04 16:15:19 +01:00
parent e913bafb1e
commit e808a4f414
No known key found for this signature in database
GPG Key ID: D7F4589C4D7F81A9

View File

@ -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;
}
}