A logging component used by Reform's Node.js applications.
This is not compatible with Reform tactical logging spec. Logger 2.x should be used for tactical applications.
Some background info:
- there are 6 log levels:
silly(5),debug(4),verbose(3),info(2),warn(1) anderror(0). - log level can be set via an environment variable
LOG_LEVEL, the default isinfo. - logging output in JSON format can be enabled by setting environment variable
JSON_PRINTtotrue, the default isfalse: - by default logging is turned off when running the unit tests.
Add it as your project's dependency:
yarn add @hmcts/nodejs-loggingRequire it:
const { Logger } = require('@hmcts/nodejs-logging')Then you can create a logger instance and use it to log information:
const logger = Logger.getLogger('app.js') // app.js is just an example, can be anything that's meaningful to youUsage are:
logger.info({
message: 'Yay, logging!'
})
or
logger.log({
level: 'info',
message: 'What time is the testing at?'
});
Above will result in the following log printed (if JSON format is enabled).
{ level: 'info',
message: 'What time is the testing at?',
label: 'app.js',
timestamp: '2017-09-30T03:57:26.875Z' }
Optionally you can use the built-in Express access logger:
const { Express } = require('@hmcts/nodejs-logging')
app.use(Express.accessLogger())Just do
yarn test
This project is licensed under the MIT License - see the LICENSE file for details.