-
Notifications
You must be signed in to change notification settings - Fork 6
/
logger.js
41 lines (35 loc) · 794 Bytes
/
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
const levels = {
ERROR: 4,
WARN: 3,
INFO: 2,
DEBUG: 1,
VERBOSE: 0
};
let level = 0;
export default {
/**
* Set log level, this value should be a string
* ERROR, WARN, INFO, DEBUG
* @param {[type]} val [description]
* @return {[type]} [description]
*/
setLevel: val => {
console.log("log level set to ", val);
level = levels[val];
},
verbose: (...args) => {
if (level <= 0) console.log("VERBOSE:", ...args);
},
debug: (...args) => {
if (level <= 1) console.log("DEBUG:", ...args);
},
info: (...args) => {
if (level <= 2) console.log("INFO:", ...args);
},
warn: (...args) => {
if (level <= 3) console.warn("WARN:", ...args);
},
error: (...args) => {
if (level <= 4) console.error("ERROR:", ...args);
}
};