-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Add option to disable request start and end logging #1629
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
Conversation
|
This is a nice solution to the problem of duplicate log messages. 👍 I wonder if it would be good to have one option that disables all built-in logs. Line 636 in 8e41b2e
Line 122 in 8e41b2e
|
|
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. |
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
mcollina
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, awesome
|
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A PR to fix it is welcome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
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