-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shim over @hmcts/nodejs-logging if present
- Loading branch information
1 parent
56c61d0
commit b56867c
Showing
2 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const colors = require('colors/safe'); | ||
const debug = require('debug'); | ||
|
||
// eslint-disable-next-line no-console | ||
const log = (prefix, ...args) => console.log(prefix, ':', ...args); | ||
|
||
module.exports = prefix => { | ||
try { | ||
// eslint-disable-next-line global-require | ||
const logger = require('@hmcts/nodejs-logging').getLogger(prefix); | ||
|
||
debug('look-and-feel.logging')('Using @hmcts/nodejs-logging for logging'); | ||
return { | ||
info(...args) { | ||
return logger.info(...args); | ||
}, | ||
warn(...args) { | ||
return logger.warn(...args); | ||
}, | ||
error(...args) { | ||
return logger.error(...args); | ||
} | ||
}; | ||
} catch (moduleMissing) { | ||
debug('look-and-feel.logging')('@hmcts/nodejs-loging not found'); | ||
debug('look-and-feel.logging')('Using console.log for logging'); | ||
return { | ||
info(...args) { | ||
return log(colors.green(prefix), ...args); | ||
}, | ||
warn(...args) { | ||
return log(colors.yellow(prefix), ...args); | ||
}, | ||
error(...args) { | ||
return log(colors.red(prefix), ...args); | ||
}, | ||
debug: debug(prefix) | ||
}; | ||
} | ||
}; |