-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitsaLog.js
109 lines (99 loc) · 2.89 KB
/
itsaLog.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Default settings to false, changed in constructor
var modSettings = {
debugModeOn: false,
infoModeOn: false,
warningModeOn: false,
debugStr: "==-- Debug: ",
errorStr: "==-- ERROR: ",
infoStr: "==-- INFO: ",
warningStr: "==-- WARNING: "
}
var modulePrint; // Set in constructor
/**
* Logger constructor
* @params moduleInput Name of the caller module
* @params settingsObject object containing modes to turn on. Modes are:
* "debugModeOn," "infoModeOn," and "warningModeOn." Note that you can also
* set their string settings as well
*/
function createLog(moduleInput, settingsObject){
modulePrint = moduleInput;
for(var element in settingsObject){
if(settingsObject.hasOwnProperty(element)){
switch(element){
case "debugModeOn":
modSettings.debugModeOn = settingsObject.debugModeOn;
break;
case "infoModeOn":
modSettings.infoModeOn = settingsObject.infoModeOn;
break;
case "warningModeOn":
modSettings.warningModeOn = settingsObject.warningModeOn;
break;
case "debugStr":
modSettings.debugStr = settingsObject.debugStr;
break;
case "infoStr":
modSettings.infoStr = settingsObject.infoStr;
break;
case "errorStr":
modSettings.errorStr = settingsObject.errorStr;
break;
case "warningStr":
modSettings.warningStr = settingsObject.warningStr;
break;
}
}
}
};
/*
* Logging functions
*/
function debug(message){
if (modSettings.debugModeOn){
try{
console.log(modSettings.debugStr + modulePrint + "." + arguments.callee.caller.name.toString() + " - " + message);
} catch (err){
console.log(modSettings.debugStr + modulePrint + " - " + message);
}
}
return true;
}
function error(message, callback){
callback = (typeof callback === 'function') ? callback : function() {};
if (!message){return false;}
try{
console.error(modSettings.errorStr + modulePrint + "." + arguments.callee.caller.name.toString() + " - " + message);
callback(message);
} catch (err) {
console.error(modSettings.errorStr + modulePrint + " - " + message);
callback(message);
}
return true;
}
function info(message){
if (modSettings.infoModeOn){
console.log(modSettings.infoStr + message);
}
return true;
}
function warning(message){
if (modSettings.warningModeOn){
try{
console.log(modSettings.warningStr + modulePrint + "." + arguments.callee.caller.name.toString() + " - " + message);
} catch(err){
console.log(modSettings.warningStr + modulePrint + " - " + message);
}
}
return true;
}
function setDebug(activationFlag){
modSettings.debugModeOn = (activationFlag == true ? true : false);
}
function setInfo(activationFlag){
modSettings.infoModeOn = (activationFlag == true ? true : false);
}
function setWarning(activationFlag){
modSettings.warningModeOn = (activationFlag == true ? true : false);
}
module.exports = {info, debug, error, warning, createLog, setWarning, setInfo, setDebug};