hapi-pino
hapi-pino copied to clipboard
Unable to log a "request" event while using "response.failaction" settings as "log" instead of throwing an error.
Hapi allows you to choose what to do when response validation fails by setting response.failAction. (ref.: https://hapijs.com/tutorials/validation#failaction)
When we set that option to:

the current way that hapi-pino is set to log requests which have the event.channel set to internal doesn't recognizes that configuration and the log message is ignored.
This is where Hapi check for the response.failAction settings
node_modules/@hapi/hapi/lib/toolkit.js

This is where Hapi creates a log payload using the internal channel
node_modules/@hapi/hapi/lib/request.js

This is where hapi-pino is ignoring the log message:
node_modules/hapi-pino/index.js

What will be the best course of action to fix this?
What will be the best course of action to fix this?
I believe we have the following options:
-
we can programmatically add more "internal" options tags to be logged, not only the
accept-encoding -
we can include the internal options tags as part of the configuration object
I would prefer the last approach.
Let me know if you agree or have a different approach and then I could help to provide the PR for that.
the latter would be be better for me
Il giorno mar 9 lug 2019 alle 18:06 Felipe Vieira Almeida < [email protected]> ha scritto:
What will be the best course of action to fix this?
I believe we have the following options:
we can programmatically add more "internal" options tags to be logged, not only the accept-encoding
we can include the internal options tags as part of the configuration object
I would prefer the last approach.
Let me know if you agree or have a different approach and then I could help to provide the PR for that.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pinojs/hapi-pino/issues/80?email_source=notifications&email_token=AAAMXYYG2V5XG3KXJYL6LCLP6SZO3A5CNFSM4H7ADHWKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODZQXZCI#issuecomment-509705353, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAMXY4EQO2CG35EFPPBHJ3P6SZO3ANCNFSM4H7ADHWA .
@fvalmeida curious if you ever tried this out? Or if you found an alternative way to log validation errors? I also require the same functionality and am willing to have a go raising a PR for this, if you no longer have the time or need for it.
If anyone else stumbles onto this, the following works to get these errors logged:
server.events.on('request', (event, tags) => {
if (tags.channel = 'internal') {
server.logger.error({req: event.raw.req, err: tags.error, tags:tags.tags}, tags.error.message);
}
});
Would you like to send a Pull Request to address this issue? Remember to add unit tests.