diff --git a/DebugLog.js b/DebugLog.js index 4a4004b21..a97031bfe 100644 --- a/DebugLog.js +++ b/DebugLog.js @@ -15,14 +15,17 @@ let thisObject = { bot: undefined, write: write, - persist: persist, + flush: flush, + persist: persist, // This method is executed at the end of each Main Loop. initialize: initialize }; - let blobContent = "["; + let accumulatedLog = "["; let disableLogging; + let flushCounter = 0; + return thisObject; function initialize(pdisableLogging) { @@ -36,6 +39,17 @@ } } + function flush() { + + /* + This method will partition the loop log file into several chuncks, each time is executed. It is intended for long processes that needs to show their advance + and release memory used by accumulating messages in this module. + */ + + flushCounter++; + persist(); + } + function persist() { /* Here we actually write the content of the in-memory log to a blob */ @@ -49,6 +63,9 @@ } + let contentToPersist = accumulatedLog; + accumulatedLog = "["; + const BLOB_STORAGE = require(ROOT_DIR + 'BlobStorage'); let cloudStorage = BLOB_STORAGE.newBlobStorage(thisObject.bot); @@ -67,13 +84,23 @@ filePath = filePath + "/" + thisObject.bot.debug.year + "/" + thisObject.bot.debug.month; } - let fileName = "Loop." + pad(thisObject.bot.loopCounter, 8) + ".json"; + let fileName; + + if (flushCounter > 0) { + + fileName = "Loop." + pad(thisObject.bot.loopCounter, 8) + "." + pad(flushCounter, 4) + ".json"; + + } else { + + fileName = "Loop." + pad(thisObject.bot.loopCounter, 8) + ".json"; + + } writeLog(); function writeLog() { - cloudStorage.createTextFile(filePath, fileName, blobContent + '\r\n' + "]", onFileCreated); + cloudStorage.createTextFile(filePath, fileName, contentToPersist + '\r\n' + "]", onFileCreated); function onFileCreated(err) { @@ -86,7 +113,7 @@ return; } - //blobContent = ""; + contentToPersist = ""; //thisObject = {}; } } @@ -95,19 +122,19 @@ console.log("[ERROR] DebugLog -> persist -> onInizialized -> cloud storge failed to initialize. "); console.log("[ERROR] DebugLog -> persist -> onInizialized -> err.message = " + err.message); - console.log("[ERROR] DebugLog -> persist -> onInizialized -> blobContent = " + blobContent); + console.log("[ERROR] DebugLog -> persist -> onInizialized -> contentToPersist = " + contentToPersist); } } catch (err) { console.log("[ERROR] DebugLog -> persist -> onInizialized -> err = " + err.message); - console.log("[ERROR] DebugLog -> persist -> onInizialized -> blobContent = " + blobContent); + console.log("[ERROR] DebugLog -> persist -> onInizialized -> contentToPersist = " + contentToPersist); } } } catch (err) { console.log("[ERROR] DebugLog -> persist -> err = " + err.message); - console.log("[ERROR] DebugLog -> persist -> onInizialized -> blobContent = " + blobContent); + console.log("[ERROR] DebugLog -> persist -> onInizialized -> contentToPersist = " + contentToPersist); } } @@ -116,6 +143,8 @@ try { + /* console.log("AACloud" + spacePad(pModule, 50) + " : " + pMessage); */ + if (disableLogging === true) { return; } if (global.CURRENT_EXECUTION_AT === "Browser") { @@ -149,7 +178,7 @@ let logLine = '\r\n' + "['" + newDate + "'," + messageId + ",'" + pModule + "','" + pMessage + "']"; - blobContent = blobContent + logLine; + accumulatedLog = accumulatedLog + logLine; } catch (err) { console.log("[ERROR] DebugLog -> write -> err = " + err.message); diff --git a/Run.js b/Run.js index 43f397803..b4789a665 100644 --- a/Run.js +++ b/Run.js @@ -3,7 +3,7 @@ global.CURRENT_ENVIRONMENT = "Develop"; global.CURRENT_EXECUTION_AT = "Cloud"; global.SHALL_BOT_STOP = false; global.USER_LOGGED_IN = "Ciencias"; -global.DEV_TEAM = "AAVikings"; +global.DEV_TEAM = "AAMasters"; global.AT_BREAKPOINT = false; // This is used only when running at the browser. process.on('uncaughtException', function (err) { diff --git a/StatusReport.js b/StatusReport.js index 915c1595f..4cd802bcd 100644 --- a/StatusReport.js +++ b/StatusReport.js @@ -184,47 +184,28 @@ if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> fileName = " + fileName); } if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> filePath = " + filePath); } - utilities.createFolderIfNeeded(filePath, cloudStorage, onFolderCreated); + let fileContent = JSON.stringify(thisObject.file); - function onFolderCreated(err) { + cloudStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - try { + function onFileCreated(err) { - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> onFolderCreated -> Entering function."); } + if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> onFileCreated -> Entering function."); } - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] save -> onFolderCreated -> err = " + err.message); - callBackFunction(err); - return; - } - - let fileContent = JSON.stringify(thisObject.file); - - cloudStorage.createTextFile(filePath, fileName, fileContent + '\n', onFileCreated); - - function onFileCreated(err) { - - if (global.LOG_CONTROL[MODULE_NAME].logInfo === true) { logger.write(MODULE_NAME, "[INFO] save -> onFolderCreated -> onFileCreated -> Entering function."); } - - if (err.result !== global.DEFAULT_OK_RESPONSE.result) { - logger.write(MODULE_NAME, "[ERROR] save -> onFolderCreated -> onFileCreated -> err = " + err.message); - callBackFunction(err); - return; - } - - if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { - logger.write(MODULE_NAME, "[INFO] save -> onFolderCreated -> onFileCreated -> Content written = " + fileContent); - } - - callBackFunction(global.DEFAULT_OK_RESPONSE); - return; - } + if (err.result !== global.DEFAULT_OK_RESPONSE.result) { + logger.write(MODULE_NAME, "[ERROR] save -> onFileCreated -> err = " + err.message); + callBackFunction(err); + return; } - catch (err) { - logger.write(MODULE_NAME, "[ERROR] save -> onFolderCreated -> err = " + err.message); - callBackFunction(global.DEFAULT_FAIL_RESPONSE); + + if (global.LOG_CONTROL[MODULE_NAME].logContent === true) { + logger.write(MODULE_NAME, "[INFO] save -> onFileCreated -> Content written = " + fileContent); } + + callBackFunction(global.DEFAULT_OK_RESPONSE); + return; } + } catch (err) { logger.write(MODULE_NAME, "[ERROR] save -> err = " + err.message);