Override console.log and console.error

This commit is contained in:
loicbersier 2020-07-11 20:27:29 +02:00
parent 221bf5cd86
commit 7eb3540e53

View file

@ -123,6 +123,31 @@ class ReadyListener extends Listener {
console.log('===========[ READY ]==========='); console.log('===========[ READY ]===========');
let logFunc = console.log;
console.log = function(){
if (process.argv.includes('--debug')) {
const date = new Date;
const hours = `${date.getHours()}`.padStart(2, '0');
const minutes = `${date.getMinutes()}`.padStart(2, '0');
const seconds = `${date.getSeconds()}`.padStart(2, '0');
logFunc.apply(console, [`[${hours}:${minutes}:${seconds}] [LOG] `].concat([].slice.call(arguments)));
}
};
if (process.argv.includes('--debug'))
console.log('Logging enabled');
let errorFunc = console.error;
console.error = function(){
const date = new Date;
const hours = `${date.getHours()}`.padStart(2, '0');
const minutes = `${date.getMinutes()}`.padStart(2, '0');
const seconds = `${date.getSeconds()}`.padStart(2, '0');
errorFunc.apply(console, [`[${hours}:${minutes}:${seconds}] [ERROR] `].concat([].slice.call(arguments)));
};
} }
} }