-
Notifications
You must be signed in to change notification settings - Fork 20
/
log.js
35 lines (32 loc) · 912 Bytes
/
log.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
const colorCodes = {
BLACK: '\x1b[30m',
RED: '\x1b[31m',
GREEN: '\x1b[32m',
YELLOW: '\x1b[33m',
BLUE: '\x1b[34m',
MAGENTA: '\x1b[35m',
CYAN: '\x1b[36m',
RESET: '\x1b[0m'
}
function getColorCode (colorName) {
const colorCode = colorCodes[colorName.toUpperCase()]
return colorCode || colorCodes.RESET
}
module.exports = (data, type, color) => {
if (data) {
let logData = `${colorCodes.CYAN}Secure-env : ${colorCodes.RESET}`
switch (type.toUpperCase()) {
case 'ERROR':
logData += `${colorCodes.RED} ERROR OCCURED ${colorCodes.RESET}`
break
case 'INFO':
logData += `${colorCodes.GREEN} INFO ${colorCodes.RESET}`
break
case 'WARN':
logData += `${colorCodes.YELLOW} WARNING ${colorCodes.RESET}`
break
}
logData += color ? `${getColorCode(color)}${data}${colorCodes.RESET}` : data
console.log(logData)
}
}