I'd like to have good ignore logging for a a specific route since it's a health check route gets polled by amazon every few seconds - it just adds noise to our logs.
Is there route specific configuration I can set for the good plugin so that it just ignores a single specific route?
I'd like to have good ignore logging for a a specific route since it's a health check route gets polled by amazon every few seconds - it just adds noise to our logs.
Is there route specific configuration I can set for the good plugin so that it just ignores a single specific route?
Share Improve this question edited Sep 28, 2015 at 22:29 Clarkie 7,5509 gold badges40 silver badges53 bronze badges asked Sep 28, 2015 at 19:02 MonkeyBonkeyMonkeyBonkey 48k82 gold badges270 silver badges479 bronze badges3 Answers
Reset to default 6Here’s something that works at least with hapi
16.1, good
7.1, and good-squeeze
5.0. The idea is to tag the health check route’s logging, and then exclude that route with good-squeeze
.
Configuring good
/good-squeeze
to exclude “health
”:
server.register({
register: Good,
options: {
reporters: {
console: [
{
module: 'good-squeeze',
name: 'Squeeze',
args: [
{
// keep health checks from appearing in logs
response: { exclude: 'health' },
log: '*',
},
],
},
{
module: 'good-console',
},
'stdout',
],
},
},
});
And then tag your route:
server.route({
method: 'GET',
path: '/admin/ok',
handler: (request, reply) => reply('ok'),
config: {
tags: ['health'],
},
});
It is possible to do. Here is the documentation https://github./hapijs/good/blob/master/API.md#stream-transforms-using-plugin-configs
Hapi route configuration
var routeConfig = {
plugins: {
good: {
suppressResponseEvent: true
}
}
};
server.route({
method: '*',
path: '/suscribe/{path*}',
handler: function(req, rep){
rep("OK!");
},
config: routeConfig
});
Creating a custom filter for good. You will need to create a new npm package. For this example, we are going to name it good-filter Follow the architecture from https://github./hapijs/good-squeeze/ The main file (index.js) contains:
'use strict';
module.exports = {
Filter: require("./filter.js")
};
This package must be available when good is loading. The following code goes into filter.js in the good-filter package.
'use strict';
const Stream = require('stream');
class Filter extends Stream.Transform {
constructor(options) {
options = Object.assign({}, options, {
objectMode: true
});
super(options);
}
_transform(data, enc, next) {
if (data.event === 'response' && data.config.suppressResponseEvent === true) {
return next();
}
return next(null, data);
}
}
module.exports = Filter;
Finally, add your filter to good configuration.
const options = {
ops: {
interval: 1000
},
reporters: {
myConsoleReporter: [{
module: 'good-squeeze',
name: 'Squeeze',
args: [{ log: '*', response: '*' }]
},
{
module: 'good-filter',
name: 'Filter',
args: [{ log: '*', response: '*' }]
},
{
module: 'good-console'
}, 'stdout']
}
};
I assume you're looking at ignoring the response
logging which isn't configurable as far as I'm aware. For other logging you can filter the events through the use of tags.
The following:
var someData = {foo:'bar'};
request.log('myTag', someData);
generates the following output:
150928/224019.555, [request,myTag], data: {"foo":"bar"}
The following good
options would pick this up:
var loggingOpts = {
reporters: [{
reporter: require('good-console'),
events: { request: 'myTag' }
}]
};