From 7eb3540e53a3aff2f428354a80c3fedc8c7046fe Mon Sep 17 00:00:00 2001 From: loicbersier Date: Sat, 11 Jul 2020 20:27:29 +0200 Subject: [PATCH] Override console.log and console.error --- event/listeners/ready.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/event/listeners/ready.js b/event/listeners/ready.js index 6d71b4d4..c8c05250 100644 --- a/event/listeners/ready.js +++ b/event/listeners/ready.js @@ -123,6 +123,31 @@ class ReadyListener extends Listener { 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))); + }; + } }