-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathlogger.js
43 lines (40 loc) · 931 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
42
43
/**
* @name Logger
*
* @desc Log execution flow in console
*/
const config = require('../config/config.json')
const enabled = config.logger.enabled
const debug = enabled && config.logger.level.toLowerCase() == 'debug'
const red = '\x1b[31m%s\x1b[0m'
const green = '\x1b[32m%s\x1b[0m'
const yellow = '\x1b[33m%s\x1b[0m'
const blue = '\x1b[34m%s\x1b[0m'
module.exports = {
info: (...messages) => {
if (enabled) {
console.log('INFO', ...messages)
}
},
warn: (...messages) => {
if (debug) {
console.log(yellow, 'WARN', ...messages)
}
},
debug: (...messages) => {
if (debug) {
console.log(blue, 'DEBUG', ...messages)
}
},
error: (...messages) => {
console.log(red, 'ERROR', ...messages)
},
test: {
pass: (...messages) => {
console.log(green, 'PASS', ...messages)
},
fail: (...messages) => {
console.log(red, 'FAIL', ...messages)
}
}
}