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

add option to log 4xx error details in request logs #182

Merged
merged 1 commit into from
May 8, 2023

Conversation

jeffmhastings
Copy link
Contributor

Fixes #111

This PR adds a new option log4xxResponseErrors that, when true, will add the error details to the response log under the key err (chosen to match 500 error logging).

For example:

{"level":30,"time":1683229159104,"pid":92186,"hostname":"jeff-MacBook-Pro","req":{"id":"1683229159103:jeff-MacBook-Pro:92186:lh9j6jej:10000","method":"get","url":"/","query":{},"headers":{"user-agent":"shot","host":"jeff-MacBook-Pro:0"},"remoteAddress":"127.0.0.1","remotePort":""},"err":{"type":"Object","message":"invalid request","stack":"","statusCode":400,"error":"Bad Request"},"res":{"statusCode":400,"headers":{"content-type":"application/json; charset=utf-8","cache-control":"no-cache","content-length":68}},"responseTime":1,"msg":"[response] get / 400 (1ms)"}

This pulls the response from the request.response.source object, which is the value returned by the lifecycle method.

@mcollina mcollina merged commit 06b4613 into hapijs:master May 8, 2023
@jeffmhastings jeffmhastings deleted the log-non-5xx-error-details branch May 8, 2023 14:03
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

Successfully merging this pull request may close these issues.

Logging non 5xx error details
2 participants