diff --git a/package.json b/package.json index b206cf9..34ad393 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "babel-loader": "^7.1.2", "babel-preset-env": "^1.6.0", "check-types": "^7.3.0", + "colors": "^1.1.2", "config": "^1.26.1", "copy-webpack-plugin": "^4.0.1", "css-loader": "^0.28.4", diff --git a/src/util/logging.js b/src/util/logging.js new file mode 100644 index 0000000..1aa52f4 --- /dev/null +++ b/src/util/logging.js @@ -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) + }; + } +};