-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.js
58 lines (49 loc) · 1.01 KB
/
logs.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
/**
* logs.js
*
* displays logs based on log level
*/
var levels = [
'always',
'warning',
'debug',
'verbose'
];
var logLevel = process.env.LOG_LEVEL || 0;
var copyArgs = function(args) {
var argsArray = [];
for(var i = 0; i < args.length; i++)
argsArray[i] = args[i];
return argsArray;
}
module.exports = {
getLevel: function() {
return levels[logLevel];
},
always: function() {
var pass = copyArgs(arguments);
pass.unshift('ALWAYS : ');
console.log.apply(this, pass);
},
warning: function() {
if(logLevel >= 1) {
var pass = copyArgs(arguments);
pass.unshift('WARNING: ');
console.log.apply(this, pass);
}
},
debug: function(log) {
if(logLevel >= 2) {
var pass = copyArgs(arguments);
pass.unshift('DEBUG : ');
console.log.apply(this, pass);
}
},
verbose: function(log) {
if(logLevel >= 3) {
var pass = copyArgs(arguments);
pass.unshift('VERBOSE: ');
console.log.apply(this, pass);
}
}
}