Add option to disable request start and end logging#1629
Conversation
|
I don't see a reason to disable the other logs. The other logs are a key feature of Fastify: integrated logging. The catch with the logs at the start and end of the request is that these logs are usually parsed tools to determine usage and performance metrics, e.g. "how many people are using my routes and with what parameters" (incoming request) and "how long are my route taking to respond with which status codes" (outgoing response). Different people have different requirements as to what information they need to accomplish those tasks. So it's difficult to provide general log statements in these situations. The proposed PR allows the user to determine if what exists is good enough for them or to provide their own implementation if necessary. That being said, feel free to submit a PR that implements whatever functionality you need. |
|
Likely next week. |
| }) | ||
|
|
||
| fastify.addHook('onResponse', (req, reply, next) => { | ||
| req.log.info({ url: req.req.originalUrl, statusCode: res.res.statusCode }, 'request completed') |
There was a problem hiding this comment.
res.res.statusCode should be reply.res.statusCode and req.log.info should be reply.log.info in next line.
There was a problem hiding this comment.
A PR to fix it is welcome.
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This addresses issue #1624. Instead of attempting to pass along a limited set of information such that it can be logged at the end of the request, which would lead to a never ending "I need this info there" path, this PR adds an option to disable the initial and final request logs. The result is you can attach your own
onRequestandonResponsehooks to log the information you need and not get double log messages due to the enforced logging in Fastify.Checklist
npm run testandnpm run benchmark