good-bunyan
is a good reporter implementation to write hapi server events to a bunyan logger.
Creates a new GoodBunyan object with the following arguments:
events
- an object of key value pairs.key
- one of the supported good events indicating the hapi event to subscribe tovalue
- a single string or an array of strings to filter incoming events. "*" indicates no filtering.null
andundefined
are assumed to be "*"
config
- configuration object with the following available keyslogger
(required) - bunyan logger instance.levels
- object used to set the default bunyan level for each good event type. Each key is a good event (ops
,repsonse
,log
,error
andrequest
), and the values must be a bunyan level (trace
,debug
,info
,error
orfatal
). Please note thatgood-bunyan
will first try to look for a valid bunyan level within the event tags (e.g. using the tag ['error', 'handler'] will result in using the bunyan 'error' level).formatters
- object used to override the message passed to buyan. Each key is a good event (ops
,repsonse
,log
,error
andrequest
), and the values must be functions which take an objectdata
as the argument and output, either astring
, or an array of arguments to be passed for the bunyan log.
Initializes the reporter with the following arguments:
stream
- a Node readable stream that will be the source of data for this reporter. It is assumed thatstream
is inobjectMode
.emitter
- an event emitter object.callback
- a callback to execute when the start function has complete all the necessary set up steps and is ready to receive data.
npm install good-bunyan --save
var Hapi = require('hapi');
var bunyan = require('bunyan');
var logger = bunyan.createLogger({ name: 'myapp' });
var server = new Hapi.Server();
server.connection({ host: 'localhost' });
var options = {
opsInterval: 1000,
responsePayload: true, // enable this to log response payloads
reporters: [{
reporter: require('good-bunyan'),
config: {
logger: logger,
levels: {
ops: 'debug'
},
formatters: {
response: function (data) {
return 'Response for' + data.path;
}
}
}
}]
};
server.register({
register: require('good'),
options: options
}, function (err) {
if (err) {
console.error(err);
}
else {
server.start(function () {
console.info('Server started at ' + server.info.uri);
});
}
});
Inspired by good-console.