-
Notifications
You must be signed in to change notification settings - Fork 17
/
logger.js
48 lines (37 loc) · 1.08 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
/**
* Simple logging class. 3 levels of log:
* INFO
* WARNING
* ERROR
* DEBUG - debug mode
* [] - None means to log everything.
*
* Log levels can be combined: [DEBUG, ERROR] etc.
*
* Author: Karol Domagala
*
*/
var Log = {
INFO : 1,
DEBUG : 2,
WARNING : 3,
ERROR : 4,
severity : [1,4], // INFO i ERROR
info : function(msg) {
if (Log.severity.length == 0 || (Log.severity && Log.severity.indexOf(Log.INFO)>=0) )
console.log(new Date().toLocaleTimeString() + ": [INFO] " + msg);
},
warning : function(msg) {
if (Log.severity.length == 0 || (Log.severity && Log.severity.indexOf(Log.WARNING)>=0))
console.log(new Date().toLocaleTimeString() + ": [WARNING] " + msg);
},
error : function(msg) {
if (Log.severity.length == 0 || (Log.severity && Log.severity.indexOf(Log.ERROR)>=0))
console.log(new Date().toLocaleTimeString() + ": [ERROR] " + msg);
},
debug : function(msg) {
if (Log.severity.length == 0 || (Log.severity && Log.severity.indexOf(Log.DEBUG)>=0))
console.log(new Date().toLocaleTimeString() + ": [DEBUG] " + msg);
}
}
exports.Log = Log;