Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to log a "request" event while using "response.failaction" settings as "log" instead of throwing an error. #80

Open
fvalmeida opened this issue Jul 8, 2019 · 6 comments

Comments

@fvalmeida
Copy link

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:

image

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
image

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

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

@mcollina
Copy link
Collaborator

mcollina commented Jul 9, 2019

What will be the best course of action to fix this?

@fvalmeida fvalmeida changed the title Unable to log request event when using response.failaction set to log instead of throw an error.. Unable to log a "request" event while using "response.failaction" settings as "log" instead of throwing an error. Jul 9, 2019
@fvalmeida
Copy link
Author

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.

@mcollina
Copy link
Collaborator

mcollina commented Jul 9, 2019 via email

@rossanthony
Copy link
Contributor

@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.

@mikeburgh
Copy link

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);
	}
});

@mcollina
Copy link
Collaborator

mcollina commented Jun 6, 2020

Would you like to send a Pull Request to address this issue? Remember to add unit tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants