This will definitely save time, and ensure more uniformity. It moves the `createServiceTester()` calls to a different place from where I'd like them, though I'm happy to have them checked by the linter. Closes #2701
43 lines
1.2 KiB
JavaScript
43 lines
1.2 KiB
JavaScript
'use strict'
|
|
|
|
const chalk = require('chalk')
|
|
const config = require('config').util.toObject()
|
|
|
|
// Config is loaded globally but it would be better to inject it. To do that,
|
|
// there needs to be one instance of the service created at registration time,
|
|
// which gets the config injected into it, instead of one instance per request.
|
|
// That way most of the current static methods could become instance methods,
|
|
// thereby gaining access to the injected config.
|
|
const {
|
|
services: { trace: enableTraceLogging },
|
|
} = config.public
|
|
|
|
function _formatLabelForStage(stage, label) {
|
|
const colorFn = {
|
|
inbound: chalk.black.bgBlue,
|
|
fetch: chalk.black.bgYellow,
|
|
validate: chalk.black.bgGreen,
|
|
unhandledError: chalk.white.bgRed,
|
|
outbound: chalk.black.bgBlue,
|
|
}[stage]
|
|
return colorFn(` ${label} `)
|
|
}
|
|
|
|
function logTrace(stage, symbol, label, content, { deep = false } = {}) {
|
|
if (enableTraceLogging) {
|
|
if (deep) {
|
|
console.log(_formatLabelForStage(stage, label), symbol)
|
|
console.dir(content, { depth: null })
|
|
} else {
|
|
console.log(_formatLabelForStage(stage, label), symbol, '\n', content)
|
|
}
|
|
return true
|
|
} else {
|
|
return false
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
logTrace,
|
|
}
|