forked from erwintoni/gb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.js
48 lines (43 loc) · 1.18 KB
/
logger.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
var warningsPrinted = 0;
var errorsPrinted = 0;
var infoPrinted = 0;
exports.warningsReceived = 0;
exports.errorsReceived = 0;
exports.infoReceived = 0;
function print(category, msg, opt_msg) {
if (opt_msg) {
console.log(category + ': ' + msg + '(' + opt_msg + ')');
} else {
console.log(category + ': ' + msg);
}
}
exports.warning = function(msg, opt_msg) {
if (warningsPrinted < process.env.LOGGER_MAX_WARNINGS) {
++warningsPrinted;
print('WARNING', msg, opt_msg);
if (warningsPrinted == process.env.LOGGER_MAX_WARNINGS) {
console.log('MAX WARNINGS HIT');
}
}
++exports.warningsReceived;
};
exports.error = function(msg, opt_msg) {
if (errorsPrinted < process.env.LOGGER_MAX_ERRORS) {
++errorsPrinted;
print('ERROR', msg, opt_msg);
if (errorPrinted == process.env.LOGGER_MAX_ERROR) {
console.log('MAX ERROR HIT');
}
}
++exports.errorsReceived;
};
exports.info = function(msg, opt_msg) {
if (infoPrinted < process.env.LOGGER_MAX_INFO) {
++infoPrinted;
print('INFO', msg, opt_msg);
if (infoPrinted == process.env.LOGGER_MAX_INFO) {
console.log('MAX INFO HIT');
}
}
++exports.infoReceived;
};