Last active
October 20, 2020 00:11
-
-
Save melbourne2991/8cb8f4f26f89f33c7e66b3c2ec64e121 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const readline = require('readline') | |
const colors = require('colors/safe') | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}) | |
const logMap = { | |
60: { | |
name: 'Fatal', | |
colors: ['bgRed'] | |
}, | |
50: { | |
name: 'Error', | |
colors: ['bgRed'] | |
}, | |
40: { | |
name: 'Warn', | |
colors: ['bgYellow', 'black'] | |
}, | |
30: { | |
name: 'Info', | |
colors: ['bgBlue'] | |
}, | |
20: { | |
name: 'Debug', | |
colors: ['bgGray'] | |
}, | |
10: { | |
name: 'Trace', | |
colors: ['bgGray'] | |
} | |
} | |
rl.on('line', function (line) { | |
try { | |
const parsed = JSON.parse(line) | |
const levelMapped = logMap[parsed.level] | |
let str = `${levelMapped.name}[${parsed.context || 'Top'}]` | |
let prefix = levelMapped.colors.reduce((str, color) => colors[color](str), str) | |
console.log(`${prefix} ${parsed.msg}`) | |
} catch (err) { | |
console.log(line) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment