Logging functionality re-written, all modules affected

This commit is contained in:
Luis Fernando Molina committed 2018-06-06 16:27:51 +02:00
1 parent dfefc0ff26
commit 2e28f86fd5
19 files changed
+1362 -1524

No files matched your search

+18 -23
View File
@@ -1,9 +1,9 @@
exports.newStatusDependencies = function newStatusDependencies(BOT, DEBUG_MODULE, STATUS_REPORT, BLOB_STORAGE, UTILITIES) {
exports.newStatusDependencies = function newStatusDependencies(BOT, logger, STATUS_REPORT, BLOB_STORAGE, UTILITIES) {
const FULL_LOG = true;
const LOG_FILE_CONTENT = false;
const MODULE_NAME = "StatusDependencies";
const MODULE_NAME = "Status Dependencies";
let thisObject = {
statusReports: new Map(),
@@ -14,18 +14,13 @@
let bot = BOT;
let ownerBot; // This is the bot owner of the Status Report. Only owners can save the report and override the existing content.
const logger = DEBUG_MODULE.newDebugLog();
logger.fileName = MODULE_NAME;
logger.bot = bot;
logger.initialize();
return thisObject;
function initialize(pStatusDependenciesConfig, pMonth, pYear, callBackFunction) {
try {
if (FULL_LOG === true) { logger.write("[INFO] initialize -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> Entering function."); }
/*
@@ -37,14 +32,14 @@
for (let i = 0; i < pStatusDependenciesConfig.length; i++) {
let statusReportModule = STATUS_REPORT.newStatusReport(BOT, DEBUG_MODULE, BLOB_STORAGE, UTILITIES);
let statusReportModule = STATUS_REPORT.newStatusReport(BOT, logger, BLOB_STORAGE, UTILITIES);
statusReportModule.initialize(pStatusDependenciesConfig[i], pMonth, pYear, onInitilized);
function onInitilized(err) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
logger.write("[ERROR] initialize -> onInitilized -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] initialize -> onInitilized -> err = " + err.message);
alreadyCalledBack = true;
callBackFunction(err);
@@ -62,32 +57,32 @@
switch (err.message) {
case global.DEFAULT_OK_RESPONSE.message: {
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pStatusDependenciesConfig[i].process);
logger.write(MODULE_NAME, "[INFO] initialize -> onLoad -> Execution finished well. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write(MODULE_NAME, "[INFO] initialize -> onLoad -> Execution finished well. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
}
case "Status Report was never created.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
}
case "Status Report is corrupt.": {
logger.write("[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write("[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> err.message = " + err.message);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> bot = " + pStatusDependenciesConfig[i].bot);
logger.write(MODULE_NAME, "[WARN] initialize -> onLoad -> Report Not Found. -> process = " + pStatusDependenciesConfig[i].process);
addReport();
return;
}
default:
{
logger.write("[ERROR] initialize -> onLoad -> Operation Failed.");
logger.write(MODULE_NAME, "[ERROR] initialize -> onLoad -> Operation Failed.");
if (alreadyCalledBack === false) {
alreadyCalledBack = true;
@@ -98,14 +93,14 @@
}
}
catch (err) {
logger.write("[ERROR] initialize -> onLoad -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] initialize -> onLoad -> err = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}
function addReport() {
if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Entering function."); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Entering function."); }
loadCount++;
@@ -120,7 +115,7 @@
thisObject.keys.push(key);
thisObject.statusReports.set(key, statusReportModule);
if (FULL_LOG === true) { logger.write("[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); }
if (FULL_LOG === true) { logger.write(MODULE_NAME, "[INFO] initialize -> addReport -> Report added to Map. -> key = " + key); }
if (loadCount === pStatusDependenciesConfig.length) {
if (alreadyCalledBack === false) {
@@ -132,7 +127,7 @@
}
} catch (err) {
logger.write("[ERROR] initialize -> err = " + err.message);
logger.write(MODULE_NAME, "[ERROR] initialize -> err = " + err.message);
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
}
}