-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Requests body is not logged in POST request #1686
Comments
This happens because the request is serialized when we create the child logger. At that time, the body is not parsed yet. So, the approach described in https://www.fastify.io/docs/latest/Logging/ is wrong. In order to log the body, you would have to log it manually with: app.addHook('preHandler', function (req, reply, next) {
if (req.body) {
req.log.info({ body: req.body }, 'parsed body')
}
next()
}) I'm tagging updating this issue as a "good first issue", updating the docs for this should be easy enough. |
Ok. |
Hello @mcollina, this issue is just to update docs ? or change the order of parser body... If I remember, the child logger is instantiated in the creation of fastify.build... It may not make sense a approach for it. I believe it's just the documentation. |
Yes! |
i had a related issue oon this when customizing the serializer in logger, i found |
@yunfan Please open your own issue with reproducible example. |
馃悰 Bug Report
Hello,
I cannot see the request body in my logs when I do POST requests to my test server.
To Reproduce
Expected behavior
The request body in the logs:
What I get
Your Environment
The text was updated successfully, but these errors were encountered: