Skip to content

Commit

Permalink
docs: fix req.body inside logger req (#1695)
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS authored and Eomm committed Jun 7, 2019
1 parent ecea232 commit 41a94c3
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions docs/Logging.md
Expand Up @@ -90,18 +90,30 @@ const fastify = require('fastify')({
url: req.url,
path: req.path,
parameters: req.parameters,
// Including the body and headers in the log could be in violation
// Including the headers in the log could be in violation
// of privacy laws, e.g. GDPR. You should use the "redact" option to
// remove sensitive fields. It could also leak authentication data in
// the logs.
body: req.body,
headers: req.headers
};
}
}
}
});
```
**Note**: The body not can serialize inside `req` method, because the request is serialized when we create the child logger. At that time, the body is not parsed yet.

See a approach to log `req.body`

```js
app.addHook('preHandler', function (req, reply, next) {
if (req.body) {
req.log.info({ body: req.body }, 'parsed body')
}
next()
})
```


*This option will be ignored by any logger other than Pino.*

Expand Down

0 comments on commit 41a94c3

Please sign in to comment.