-
Notifications
You must be signed in to change notification settings - Fork 15
/
jsLogger.js
49 lines (45 loc) · 1.4 KB
/
jsLogger.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
window.console = (function (origConsole) {
if (!window.console || !origConsole) {
origConsole = {};
}
var isDebug = false, isSaveLog = false,
logArray = {
logs: [],
errors: [],
warns: [],
infos: []
};
return {
log: function () {
this.addLog(arguments, "logs");
isDebug && origConsole.log && origConsole.log.apply(origConsole, arguments);
},
warn: function () {
this.addLog(arguments, "warns");
isDebug && origConsole.warn && origConsole.warn.apply(origConsole, arguments);
},
error: function () {
this.addLog(arguments, "errors");
isDebug && origConsole.error && origConsole.error.apply(origConsole, arguments);
},
info: function (v) {
this.addLog(arguments, "infos");
isDebug && origConsole.info && origConsole.info.apply(origConsole, arguments);
},
debug: function (bool) {
isDebug = bool;
},
saveLog: function (bool) {
isSaveLog = bool;
},
addLog: function (arguments, array) {
if (!isSaveLog) {
return;
}
logArray[array || "logs"].push(arguments);
},
logArray: function () {
return logArray;
}
};
}(window.console));