vizia-logger
v4.0.2
Published
Common vizia logger module.
Downloads
23
Readme
vizia-logger
The unified logger for vizia.
Usage
It is convenient to create a loggers
module to expose a logger object:
// loggers.js
const createLogger = require('vizia-logger');
const options = {}; // See the options table below.
const loggers = createLogger(options);
module.exports = loggers;
This loggers
object has the fields logger
, requestLoggerMiddleware
and responseTimeLogger
.
It's also convenient to have a second wrapper module to export the logger
field:
// logger.js
module.exports = require('./loggers').logger;
options
| field | default | required | description |
| ---------------------- | -------- | -------------------------------- | -------------------------------------------------------------------------------------------------------------- |
| name
| N/A | true | The name of your application. It is recommended to use the name field of your package.json. |
| level
| 'info'
| false | The minimum bunyan log level. Lower levels will not be logged. |
| middlewareLogLevel
| 'debug'
| false | Sets the log level of the middleware. Accepted values: ['trace', 'debug', 'info', 'warn', 'error', 'fatal']
|
| serializers
| {}
| false | Custom serializers to add to the bunyan logger. |
loggers.logger
A bunyan logger. See the bunyan documentation for more information on usage.
loggers.requestLoggerMiddleware
A middleware function which logs incoming requests. Add this to your express
stack early. It provides you with a req.logger
method which is a child logger.
Log output from req.logger
will have a UUID so that all logs for a request can
be collected. The UUID will be added to the headers of the response as
X-Request-ID
.
loggers.responseTimeMiddleware
A middleware function which appends a X-Response-Time
header with the response
time in milliseconds.