const chalkModule = require('chalk');
const chalk = chalkModule.default || chalkModule;
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.gray('[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