Skip to content

Commit

Permalink
Shim over @hmcts/nodejs-logging if present
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldfallen committed Feb 26, 2018
1 parent 56c61d0 commit b56867c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
40 changes: 40 additions & 0 deletions src/util/logging.js
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)
};
}
};

0 comments on commit b56867c

Please sign in to comment.