hapi process monitoring
Lead Maintainer: Adam Bretz
good is a Hapi process monitor. It listens for events emitted by Hapi Server instances and allows custom reporters to be registered that output subscribed events.
For example:
var Hapi = require('hapi');
var server = new Hapi.Server();
server.connection({ host: 'localhost' });
var options = {
opsInterval: 1000,
filter:{
access_token: 'censor'
},
reporters: [{
reporter: require('good-console'),
events: { log: '*', response: '*' }
}, {
reporter: require('good-file'),
events: { ops: '*' },
config: './test/fixtures/awesome_log'
}, {
reporter: 'good-http',
events: { error: '*' },
config: {
endpoint: 'http://prod.logs:3000',
wreck: {
headers: { 'x-api-key' : 12345 }
}
}
}]
};
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);
});
}
});
This example does the following:
- Sets up the
GoodConsole
reporter listening for 'response' and 'log' events. - Sets up the
GoodFile
reporter to listen for 'ops' events and log them to./test/fixtures/awesome_log
according to the file rules listed in the good-file documentation. - Sets up the
GoodHttp
reporter to listen for error events and POSTs them tohttp://prod.logs:3000
with additional settings to pass intoWreck
NOTE: Ensure calling server.connection
prior to registering Good
. request
and response
event listeners are only registered on connections that exist on server
at the time Good
is registered.
Log messages are created with tags. Usually a log will include a tag to indicate if it is related to an error or info along with where the message originates. If, for example, the console should only output error's that were logged you can use the following configuration:
var options = {
reporters: [{
reporter: require('good-console'),
events: { log: ['error', 'medium'] }
}]
};
This will now only log 'log' events that have the 'error' or 'medium' tag attached to them. Any 'log' events without one of those tags will be ignored.
This is a list of good-reporters under the hapijs umbrella:
Here are some additional reporters that are available from the hapijs community:
See the API Reference.