forked from NarrativeScience-old/log.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogging.js
40 lines (33 loc) · 865 Bytes
/
logging.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
/* Generic logging module.
*
* Log Levels:
* - 3 (Debug)
* - 2 (Info)
* - 1 (Warn)
* - 0 (Error)
*/
var Logger = function(log_level) {
this._log_level = log_level ? log_level : 2
}
Logger.prototype = {
_timestamp: function(msg) {
return (new Date()).toLocaleString().slice(0,24);
},
debug: function(msg) {
if (this._log_level < 3) { return; }
console.info("[" + this._timestamp() + "] DEBUG: " + msg);
},
info: function(msg) {
if (this._log_level < 2) { return; }
console.info("[" + this._timestamp() + "] INFO: " + msg);
},
warn: function(msg) {
if (this._log_level < 1) { return; }
console.warn("[" + this._timestamp() + "] WARN: " + msg);
},
error: function(msg) {
if (this._log_level < 0) { return; }
console.error("[" + this._timestamp() + "] ERROR: " + msg);
}
}
exports.Logger = Logger;