p3x-redis-ui-server
Version:
🏍️ The p3x-redis-ui-server package motor that is connected to the p3x-redis-ui-material web user interface
43 lines (34 loc) • 1.47 kB
JavaScript
const chalk = require('chalk');
const consoleStamp = () => {
// overriding the console should be after this!!!
console.warn = console.log
const methods = ['log', 'info', 'warn', 'error', 'debug']
const originalMethods = {}
for(let method of methods) {
originalMethods[method] = console[method]
console[method] = function() {
if (arguments[0]) {
let label
switch(method) {
case 'error':
label = chalk`{bold.red ${method.toUpperCase()}}`;
break;
case 'warn':
label = chalk`{bold.blue ${method.toUpperCase()}}`;
break;
default:
label = chalk`{green ${method.toUpperCase()}}`;
}
let data = '' //chalk`${moment().format(`YYYY/MM/DD HH:mm:ss.SSS`)} `
data += chalk`{black.grey [P3XRS]}` + ` [PID: ${(String(process.pid).padStart(6, 0))}] [${label.padStart(5, ' ')}]: `
//arguments[0] = data + arguments[0]
const mainArguments = Array.prototype.slice.call(arguments);
mainArguments.unshift(data);
originalMethods[method].apply(null, mainArguments)
} else {
originalMethods[method].apply(null, arguments)
}
}
}
}
module.exports = consoleStamp