Update debug to add a key, when set exit the app on error

.env key "EXIT_ON_ERROR"
This commit is contained in:
Logan Cusano
2023-03-11 16:30:22 -05:00
parent ea33b13a87
commit 07522c0c19

View File

@@ -1,5 +1,7 @@
// Debug
const debug = require('debug');
// Read .env file to process.env
require('dotenv').config();
/**
* Create the different logging methods for a function
@@ -13,6 +15,10 @@ exports.DebugBuilder = class DebugBuilder {
this.DEBUG = debug(`${appName}:${fileName}:DEBUG`);
this.VERBOSE = debug(`${appName}:${fileName}:VERBOSE`);
this.WARN = debug(`${appName}:${fileName}:WARNING`);
this.ERROR = debug(`${appName}:${fileName}:ERROR`).then(process.exit());
this.ERROR = (...messageParts) => {
const error = debug(`${appName}:${fileName}:ERROR`);
error(messageParts);
if (process.env.EXIT_ON_ERROR) process.exit();
}
}
}