25 lines
1.1 KiB
JavaScript
25 lines
1.1 KiB
JavaScript
// Debug
|
|
const debug = require('debug');
|
|
// Read .env file to process.env
|
|
require('dotenv').config();
|
|
|
|
/**
|
|
* Create the different logging methods for a function
|
|
* Namespace template = ("[app]:[fileName]:['INFO', 'WARNING', 'DEBUG', 'ERROR']")
|
|
* @param {string} appName The name of the app to be used in the 'app' portion of the namespace
|
|
* @param {string} fileName The name of the file calling the builder to be used in the 'fileName' portion of the namespace
|
|
*/
|
|
exports.DebugBuilder = class DebugBuilder {
|
|
constructor(appName, fileName) {
|
|
this.INFO = debug(`${appName}:${fileName}:INFO`);
|
|
this.DEBUG = debug(`${appName}:${fileName}:DEBUG`);
|
|
this.VERBOSE = debug(`${appName}:${fileName}:VERBOSE`);
|
|
this.WARN = debug(`${appName}:${fileName}:WARNING`);
|
|
this.ERROR = (...messageParts) => {
|
|
const error = debug(`${appName}:${fileName}:ERROR`);
|
|
error(messageParts);
|
|
if (process.env.EXIT_ON_ERROR && process.env.EXIT_ON_ERROR > 0) setTimeout(process.exit, process.env.EXIT_ON_ERROR_DELAY ?? 0);
|
|
}
|
|
}
|
|
}
|