From 9101d7b2e259c9c9b423e000fb6fda558d572919 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Sun, 22 Apr 2018 18:57:03 +0200 Subject: [PATCH] Server Module Logging Improved --- .vs/AAWeb/v15/.suo | Bin 49152 -> 49152 bytes server.js | 93 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 20 deletions(-) diff --git a/.vs/AAWeb/v15/.suo b/.vs/AAWeb/v15/.suo index ddc7754329e6a0f63fcc9372993a1f9e758507f4..52ee79ef6d3dc1a18bf87335107493e3647763d7 100644 GIT binary patch delta 375 zcmZo@U~Xt&-jKt@>L6J1Bx-XZ({E&|oyVimht$7pC)*53?CE zdTsv7uFNRl0hIX<1fD?pACR7`!70NV3>6Fk((w}mwI^}0OxECT*u?dOY4Z~<8OBX~ zB}|h`_%2L#5j2=w!r!w=sDx>AiAMnAU}k*z8bqfO%07%Vfh^t<73Z*BB>nR8`olQ1O6$vS4T9WP|c~ljYkV zLS?TrPG;9Z-j`H^()wF~W3g2I^p%oYFXF@`t$sn*~}vFiw_l7T&ym zMj+$lb2CLYS9HH&Tr`1c(K4n<{TdoE430n;&XCHG#1O+!45W(~%7EmZtks;hc0YEx uINrPF_WgOwbYeWDtTaA4H delta 614 zcmZXQe@IhN6vywq@9oWPHs5MnW;3@&Fa}98iXe*(hFDo3Wd#lTp%sKQE!W~f?7n6} zvN?KZMMO}&e~r>zC|nu#XZ=$U7(_&W1VVpBG>Zh+c~*aQ;d9U7`#tB}ADl~^OOu1l zHk7@s_lRM(D7k|#r}yr8|CVkfgz!zEDH@%D8q2dP1pciObMbNY6Q*ui~1qs z%Tb@G`Hsk)OE}tMHTuoS8l(kTiv*BXWF69mSal(c>ya=b3N7L8En6|8e_5Fz337;> zBqvBaIZp=3*=6g08AkdKHjot7r143^<*?B&gCpUmeGosz%>gE6wFN2`PCFG>sF9FW zcz{BR5Y&&tzLFg_ry~%(FfVvI&fpFAz}3&lO$hS96lMQy7roSYZVe zjjv83;dQKKP4~%G2BBhS!{OIXD<|-3e49~@04+7EAI?lTcI^CFO(s6hb^Vwhh5Msj zzWj38pY0X~>o=32^FDKonGY4Sz|4EBGESMGkLz~RV1~hAj&Fw Entering function."); } readEcosystemConfig(); function readEcosystemConfig() { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readEcosystemConfig -> Entering function."); } + /* This configuration file is the backbone of the system. The first file we are going to get is a template where other configurations are @@ -93,11 +91,7 @@ function initialize() { function readCompetitionsConfig() { - if (CONSOLE_LOG === true) { - - console.log("I am entering the readCompetitionsConfig function."); - - } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> Entering function."); } /* @@ -138,6 +132,9 @@ function initialize() { function onFileRead(err, pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onFileRead -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onFileRead -> fileName = " + fileName); } + try { responsesReceived++; @@ -175,6 +172,10 @@ function initialize() { function onDataArrived(pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> host.codeName = " + host.codeName); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> competition.repo = " + competition.repo); } + try { if (CONSOLE_LOG === true) { @@ -228,6 +229,9 @@ function initialize() { function onFileRead(err, pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onFileRead -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onFileRead -> fileName = " + fileName); } + try { responsesReceived++; @@ -265,6 +269,10 @@ function initialize() { function onDataArrived(pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> host.codeName = " + host.codeName); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readCompetitionsConfig -> onDataArrived -> competition.repo = " + competition.repo); } + try { if (CONSOLE_LOG === true) { @@ -305,11 +313,8 @@ function initialize() { function readBotsAndPlottersConfig() { - if (CONSOLE_LOG === true) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> Entering function."); } - console.log("I am entering the readBotsAndPlottersConfig function."); - - } /* Each bot has its configuration at its own repo since each team must be able to change it at will. @@ -344,6 +349,9 @@ function initialize() { function onFileRead(err, pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onFileRead -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onFileRead -> fileName = " + fileName); } + try { responsesReceived++; @@ -381,6 +389,10 @@ function initialize() { function onDataArrived(pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> host.codeName = " + host.codeName); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> competition.repo = " + competition.repo); } + try { if (CONSOLE_LOG === true) { @@ -434,6 +446,9 @@ function initialize() { function onFileRead(err, pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onFileRead -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onFileRead -> fileName = " + fileName); } + try { responsesReceived++; @@ -471,6 +486,10 @@ function initialize() { function onDataArrived(pData) { + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> host.codeName = " + host.codeName); } + if (CONSOLE_LOG === true) { console.log("[INFO] initialize -> readBotsAndPlottersConfig -> onDataArrived -> competition.repo = " + competition.repo); } + try { if (CONSOLE_LOG === true) { @@ -512,11 +531,7 @@ function initialize() { function startHtttpServer() { - if (CONSOLE_LOG === true) { - - console.log("I am entering the startHtttpServer function. So far so good."); - - } + if (CONSOLE_LOG === true) { console.log("[INFO] startHtttpServer -> Entering function."); } try { @@ -529,6 +544,9 @@ function startHtttpServer() { function onBrowserRequest(request, response) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> Entering function."); } + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> request = " + request); } + var htmlResponse; var requestParameters = request.url.split("/"); @@ -559,6 +577,8 @@ function onBrowserRequest(request, response) { function onFileRead(err, file) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> Entering function."); } + try { let fileContent = file.toString(); @@ -580,6 +600,8 @@ function onBrowserRequest(request, response) { function addToFileContent(pDevTeamsOrHosts) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addToFileContent -> Entering function."); } + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { let devTeam = pDevTeamsOrHosts[i]; @@ -643,6 +665,8 @@ function onBrowserRequest(request, response) { function onFileRead(err, file) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> Entering function."); } + try { let fileContent = file.toString(); @@ -664,6 +688,8 @@ function onBrowserRequest(request, response) { function addToFileContent(pDevTeamsOrHosts) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addToFileContent -> Entering function."); } + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { let devTeam = pDevTeamsOrHosts[i]; @@ -731,6 +757,8 @@ function onBrowserRequest(request, response) { function onFileRead(err, file) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> Entering function."); } + try { let fileContent = file.toString(); @@ -823,6 +851,8 @@ function onBrowserRequest(request, response) { function onFileRead(err, file) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> Entering function."); } + try { let fileContent = file.toString(); @@ -832,6 +862,8 @@ function onBrowserRequest(request, response) { function addPlotters() { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addPlotters -> Entering function."); } + let htmlLinePlotter = '' + '\n' + ' ' @@ -846,6 +878,8 @@ function onBrowserRequest(request, response) { function addScript(pDevTeamsOrHosts) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addPlotters -> addScript -> Entering function."); } + for (let i = 0; i < pDevTeamsOrHosts.length; i++) { let devTeam = pDevTeamsOrHosts[i]; @@ -894,6 +928,8 @@ function onBrowserRequest(request, response) { function addImages() { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addImages -> Entering function."); } + const htmlLine = '' + '\n' + ' ' @@ -903,6 +939,8 @@ function onBrowserRequest(request, response) { function addScript(pDevTeams) { + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> onFileRead -> addImages -> addScript -> Entering function."); } + for (let i = 0; i < pDevTeams.length; i++) { let devTeam = pDevTeams[i]; @@ -993,6 +1031,9 @@ function onBrowserRequest(request, response) { } function sendResponseToBrowser(htmlResponse) { + + if (CONSOLE_LOG === true) { console.log("[INFO] onBrowserRequest -> sendResponseToBrowser -> Entering function."); } + response.writeHead(200, { 'Content-Type': 'text/html' }); response.write(htmlResponse); @@ -1002,6 +1043,8 @@ function onBrowserRequest(request, response) { function respondWithContent(content, response) { + if (CONSOLE_LOG === true) { console.log("[INFO] respondWithContent -> Entering function."); } + try { response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. @@ -1022,6 +1065,8 @@ function respondWithContent(content, response) { function respondWithFile(fileName, response) { + if (CONSOLE_LOG === true) { console.log("[INFO] respondWithFile -> Entering function."); } + let fs = require('fs'); try { @@ -1029,6 +1074,8 @@ function respondWithFile(fileName, response) { function onFileRead(err, file) { + if (CONSOLE_LOG === true) { console.log("[INFO] respondWithFile -> onFileRead -> Entering function."); } + try { let htmlResponse = file.toString(); @@ -1056,6 +1103,8 @@ function respondWithFile(fileName, response) { function returnEmptyArray() { + if (CONSOLE_LOG === true) { console.log("[INFO] respondWithFile -> returnEmptyArray -> Entering function."); } + response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. response.setHeader("Pragma", "no-cache"); // HTTP 1.0. response.setHeader("Expires", "0"); // Proxies. @@ -1069,6 +1118,8 @@ function respondWithFile(fileName, response) { function getGithubData(pOrg, pRepo, pPath, callBackFunction) { + if (CONSOLE_LOG === true) { console.log("[INFO] getGithubData -> Entering function."); } + let cacheVersion = githubData.get(pOrg + '.' + pRepo + '.' + pPath) if (cacheVersion !== undefined) { @@ -1104,9 +1155,11 @@ function getGithubData(pOrg, pRepo, pPath, callBackFunction) { function onContent(error, result) { + if (CONSOLE_LOG === true) { console.log("[INFO] getGithubData -> onContent -> Entering function."); } + if (CONSOLE_LOG === true) { - console.log("getGithubData - Github.com responded to request " + pOrg + '.' + pRepo + '.' + pPath + " with result = " + result.toString().substring(0,100)); + console.log("[INFO] getGithubData -> onContent -> Github.com responded to request " + pOrg + '.' + pRepo + '.' + pPath + " with result = " + result.toString().substring(0,100)); }