mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
Major logging changes
This commit is contained in:
parent
fbf5a99cfd
commit
fde527aaeb
5 changed files with 83 additions and 78 deletions
36
actions.js
36
actions.js
|
@ -221,7 +221,7 @@ class QuestionDB {
|
|||
|
||||
function Process(d, file) {
|
||||
try {
|
||||
logger.Log("[PCES]:\tFile: " + file);
|
||||
logger.Log("File: " + file);
|
||||
if (d.data.split("\n").length > 1) {
|
||||
var oldFile = utils.ReadFile(file);
|
||||
var newFile = oldFile + "\n";
|
||||
|
@ -234,26 +234,26 @@ function Process(d, file) {
|
|||
var oldRes = CheckData(oldFile);
|
||||
|
||||
if (oldRes.count > 0)
|
||||
logger.Log("[NLOD]:\t\told public result: " + oldRes.count, logger.GetColor("blue"));
|
||||
logger.Log("\t\told public result: " + oldRes.count, logger.GetColor("blue"));
|
||||
else
|
||||
logger.Log("[NLOD]:\t\told public NLOD error, " + oldRes.log, logger.GetColor("redbg"), true);
|
||||
logger.Log("\t\told public NLOD error, " + oldRes.log, logger.GetColor("redbg"), true);
|
||||
|
||||
if (newRes.count > 0)
|
||||
logger.Log("[NLOD]:\t\tnew file result: " + newRes.count, logger.GetColor("blue"));
|
||||
logger.Log("\t\tnew file result: " + newRes.count, logger.GetColor("blue"));
|
||||
else
|
||||
logger.Log("[NLOD]:\t\tnew file NLOD error, " + newRes.log, logger.GetColor("redbg"), true);
|
||||
logger.Log("\t\tnew file NLOD error, " + newRes.log, logger.GetColor("redbg"), true);
|
||||
|
||||
utils.WriteFile(newFile, file);
|
||||
logger.Log("[NLOD]:\t\tNew data written to: " + file);
|
||||
logger.Log("\t\tNew data written to: " + file);
|
||||
|
||||
return newRes.count - oldRes.count;
|
||||
} else
|
||||
logger.Log("[PCES]:\t\tNo new data");
|
||||
logger.Log("\t\tNo new data");
|
||||
|
||||
|
||||
} catch (e) {
|
||||
Beep();
|
||||
logger.Log("[ERR ]:\tError at processing data! File: " + file, logger.GetColor("redbg"));
|
||||
logger.Log("\tError at processing data! File: " + file, logger.GetColor("redbg"));
|
||||
logger.Log(e.toString(), logger.GetColor("redbg"));
|
||||
}
|
||||
return -1;
|
||||
|
@ -262,7 +262,7 @@ function Process(d, file) {
|
|||
function ProcessIncomingRequest(data) {
|
||||
|
||||
if (data == undefined) {
|
||||
logger.Log("[PCES]:\tRecieved data is undefined!", logger.GetColor("redbg"));
|
||||
logger.Log("\tRecieved data is undefined!", logger.GetColor("redbg"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -291,7 +291,7 @@ function ProcessIncomingRequest(data) {
|
|||
data.AddQuestion(d.subj, q);
|
||||
}
|
||||
|
||||
logger.Log("[PCES]:\t" + d.subj);
|
||||
logger.Log("\t" + d.subj);
|
||||
var msg = "All / new count: " + allQuestions.length + " / " + questions.length;
|
||||
if (d.version != undefined)
|
||||
msg += ". Version: " + d.version;
|
||||
|
@ -310,10 +310,10 @@ function ProcessIncomingRequest(data) {
|
|||
msg += " - Data file written!";
|
||||
var color = logger.GetColor("blue");
|
||||
}
|
||||
logger.Log("[PCES]:\t" + msg, color);
|
||||
logger.Log("\t" + msg, color);
|
||||
|
||||
} catch (e) {
|
||||
logger.Log("[PCES]: Couldnt parse JSON data, trying old format...", logger.GetColor("redbg"));
|
||||
logger.Log("Couldnt parse JSON data, trying old format...", logger.GetColor("redbg"));
|
||||
var d = SetupData(data);
|
||||
var qcount = -1;
|
||||
try {
|
||||
|
@ -325,7 +325,7 @@ function ProcessIncomingRequest(data) {
|
|||
qcount = count;
|
||||
} catch (e) {console.log("Error :c"); console.log(e);}
|
||||
|
||||
logger.Log("[PCES]:\tProcessing data: " + d.subj + " (" + d.type + "), count: " + qcount, logger.GetColor("green"));
|
||||
logger.Log("\tProcessing data: " + d.subj + " (" + d.type + "), count: " + qcount, logger.GetColor("green"));
|
||||
if (d.subj == undefined){
|
||||
logger.Log(JSON.stringify(d), logger.GetColor("red"));
|
||||
return;
|
||||
|
@ -346,14 +346,14 @@ function PrintNewCount(d, newItems, file) {
|
|||
for (var i = 0; i < splitted.length; i++)
|
||||
if (splitted[i].startsWith("?"))
|
||||
count++;
|
||||
logger.Log("[NEW ]:\t" + file + " All / New: " + count + " / " + newItems, logger.GetColor("cyan"));
|
||||
logger.Log("\t" + file + " All / New: " + count + " / " + newItems, logger.GetColor("cyan"));
|
||||
}
|
||||
}
|
||||
|
||||
function SetupData(data) {
|
||||
var pdata = data.split("<#>");
|
||||
if (pdata.length <= 0){
|
||||
logger.Log("[SUPD]: Data length is zero !", logger.GetColor("redbg"));
|
||||
logger.Log("Data length is zero !", logger.GetColor("redbg"));
|
||||
throw "No data recieved!";
|
||||
}
|
||||
|
||||
|
@ -363,7 +363,7 @@ function SetupData(data) {
|
|||
if (td.length == 2)
|
||||
d[td[0]] = td[1];
|
||||
else {
|
||||
logger.Log("[SUPD]: Invalid parameter!", logger.GetColor("redbg"));
|
||||
logger.Log("Invalid parameter!", logger.GetColor("redbg"));
|
||||
throw "Invalid parameter recieved!";
|
||||
}
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ function CheckData(data) {
|
|||
var presult = NLoad(data);
|
||||
return presult;
|
||||
} catch (e) {
|
||||
logger.Log("[NLOD]: NLOD error, " + e.toString(), logger.GetColor("redbg"), true);
|
||||
logger.Log("Load error, " + e.toString(), logger.GetColor("redbg"), true);
|
||||
return {
|
||||
count: -1,
|
||||
log: [e.toString()]
|
||||
|
@ -500,7 +500,7 @@ function LoadJSON(resource) {
|
|||
}
|
||||
return r;
|
||||
} catch (e) {
|
||||
logger.Log("[LOAD]:Error loading sutff", logger.GetColor("redbg"), true);
|
||||
logger.Log("Error loading sutff", logger.GetColor("redbg"), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue