colorful logs
This commit is contained in:
parent
f8ed8e244d
commit
e15dc7902c
@ -19,16 +19,15 @@ function dateFormat (date) {
|
||||
}
|
||||
|
||||
// Console.log/error/warn "middleware" - add timestamp and write to file
|
||||
function stampAndWrite (fnc, prfx, message) {
|
||||
function stampAndWrite (fnc, color, prfx, message) {
|
||||
let prefix = '[' + prfx + '] [' + dateFormat(new Date()) + '] '
|
||||
message = prefix + message
|
||||
message = color + prefix + message
|
||||
message = message.replace(/\\u001b/g, '\x1b')
|
||||
|
||||
if (lfs) {
|
||||
lfs.write(message + '\n')
|
||||
lfs.write(message.replace(/(\u001b\[\d\d?m)/g, '') + '\n')
|
||||
}
|
||||
|
||||
message = message.replace(/\\u001b/g, '\x1b')
|
||||
|
||||
fnc.call(this, message)
|
||||
}
|
||||
|
||||
@ -36,19 +35,19 @@ function stampAndWrite (fnc, prfx, message) {
|
||||
const realConsoleLog = console.log
|
||||
console.log = function () {
|
||||
let message = util.format.apply(null, arguments)
|
||||
stampAndWrite.call(this, realConsoleLog, 'info', message)
|
||||
stampAndWrite.call(this, realConsoleLog, '', 'info', message)
|
||||
}
|
||||
|
||||
const realConsoleWarn = console.warn
|
||||
console.warn = function () {
|
||||
let message = util.format.apply(null, arguments)
|
||||
stampAndWrite.call(this, realConsoleWarn, 'warn', message)
|
||||
stampAndWrite.call(this, realConsoleWarn, '\x1b[33m', 'warn', message)
|
||||
}
|
||||
|
||||
const realConsoleError = console.error
|
||||
console.error = function () {
|
||||
let message = util.format.apply(null, arguments)
|
||||
stampAndWrite.call(this, realConsoleError, ' err', message)
|
||||
stampAndWrite.call(this, realConsoleError, '\x1b[31m', ' err', message)
|
||||
}
|
||||
|
||||
async function initializeLogger () {
|
||||
|
Reference in New Issue
Block a user