Added logging

This commit is contained in:
Kallum Jones
2022-08-03 16:52:24 +01:00
parent 765920f80c
commit 8a927d2f02
5 changed files with 311 additions and 5 deletions

View File

@ -1,13 +1,18 @@
#!/usr/bin/env node
import { Command } from "commander";
import {Command} from "commander";
import InitCommand from "./commands/init_command.js";
import InstallCommand from "./commands/install_command.js";
import Subcommand from "./commands/subcommand.js";
import Initialiser from "./util/initialiser.js";
import PrintUtils from "./util/print_utils.js";
//import PrettyError from "pretty-error";
import path from "path";
import {Logger, pino} from "pino"
export default class ModManager {
public static logger: Logger | null = null;
private static readonly LOG_FILE: string = path.join(Initialiser.getModManagerFolderPath(), "logs", `${new Date().valueOf()}.log.json`);
private static program: Command = new Command();
private static subcommands: Array<Subcommand> = [
@ -16,8 +21,10 @@ export default class ModManager {
];
static init() {
//const pe = new PrettyError();
//pe.start();
if (Initialiser.isInitialised()) {
this.logger = ModManager.createLogger();
}
this.program
.name('mod-manager')
@ -37,6 +44,16 @@ export default class ModManager {
PrintUtils.error("Mod Manager is not initialised");
}
}
static createLogger(): Logger {
let logger = pino({base: {pid: undefined, hostname: undefined}}, pino.destination({dest: this.LOG_FILE}));
process.on("uncaughtException", error => {
logger.error(error);
setTimeout(() => process.exit(1), 1)
})
return logger;
}
}
ModManager.init();