|
|
@ -6,38 +6,47 @@ class Debug { |
|
|
|
this.name = moduleName || 'unnamed module'; |
|
|
|
this.name = moduleName || 'unnamed module'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
push(req, debugMsg){ |
|
|
|
push(req, value){ |
|
|
|
if (!_.isEmpty(req.clean) && req.clean.enableDebug){ |
|
|
|
if (!req || _.isEmpty(req.clean) || !req.clean.enableDebug){ |
|
|
|
req.debug = req.debug || []; |
|
|
|
return; |
|
|
|
// remove the extra space character
|
|
|
|
|
|
|
|
req.debug.push({[this.name]: debugMsg}); |
|
|
|
|
|
|
|
// req.debug.push(`[${this.name}] ${debugMsg}`);
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
req.debug = req.debug || []; |
|
|
|
// optional debugMsg passed to timer
|
|
|
|
switch(typeof value) { |
|
|
|
beginTimer(req, debugMsg){ |
|
|
|
case 'function': |
|
|
|
if (!_.isEmpty(req.clean) && req.clean.enableDebug){ |
|
|
|
req.debug.push({[this.name]: value()}); |
|
|
|
// internal object debugTimers. Doesn't get displayed in geocodeJSON
|
|
|
|
break; |
|
|
|
req.debugTimers = req.debugTimers || {}; |
|
|
|
default: |
|
|
|
req.debugTimers[this.name] = Date.now(); |
|
|
|
req.debug.push({[this.name]: value}); |
|
|
|
if (debugMsg){ |
|
|
|
|
|
|
|
this.push(req, `Timer Began: ${debugMsg}`); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.push(req, `Timer Began`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
stopTimer(req, debugMsg){ |
|
|
|
beginTimer(req, debugMsg){ |
|
|
|
if (!_.isEmpty(req.clean) && req.clean.enableDebug){ |
|
|
|
if (req && !_.isEmpty(req.clean) && req.clean.enableDebug){ |
|
|
|
let timeElapsed = Date.now() - req.debugTimers[this.name]; |
|
|
|
// debugMsg is optional
|
|
|
|
if (debugMsg){ |
|
|
|
this.push(req, () => { |
|
|
|
this.push(req, `Timer Stopped: ${timeElapsed} ms: ${debugMsg}`); |
|
|
|
if (debugMsg){ |
|
|
|
} else { |
|
|
|
return `Timer Began. ${debugMsg}`; |
|
|
|
this.push(req, `Timer Stopped: ${timeElapsed} ms`); |
|
|
|
} else { |
|
|
|
|
|
|
|
return `Timer Began`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
return Date.now(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stopTimer(req, startTime, debugMsg){ |
|
|
|
|
|
|
|
if (req && !_.isEmpty(req.clean) && req.clean.enableDebug){ |
|
|
|
|
|
|
|
let timeElapsed = Date.now() - startTime; |
|
|
|
|
|
|
|
this.push(req, () => { |
|
|
|
|
|
|
|
if (debugMsg){ |
|
|
|
|
|
|
|
return `Timer Stopped. ${timeElapsed} ms. ${debugMsg}`; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return `Timer Stopped. ${timeElapsed} ms`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
module.exports = Debug; |
|
|
|
module.exports = Debug; |
|
|
|