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
Request logging customization #4463
Comments
If accepted, we could send a PR. |
I think it would be better to make it a factory function option that gets cached as we do with other things of this nature. It would remove the function invocation cost at every request and make it a symbol lookup. Otherwise, seems reasonable to me. |
@jsumners Can you point to any part of existing code that does this? |
How would that work if we may need to dynamically recalculate the message for every request? |
Your original statement was suggesting only the replacement of the text string "incoming request". The dynamic nature of the replacement was not explicitly stated. In that case, yes, it would need to be a function. |
I mentioned that it would make sense to incorporate request details, otherwise not much benefit over original |
I would not change that log, since it is much easier adding a The big deal here would be: could we create a plugin that adds those hooks AND takes control of the |
Hello, I want to attempt to tackle this issue. Please let me know if this issue no longer needs assistance. |
Sure, how do you plan to tackle this issue? |
Ok thanks! I would like to create a request param log message which will provide a detailed overview of each request, ideally something that is similar to the layout of Window's Event Viewer. I also think kibertoad's original idea to create a new function called createRequestLogMessage(req) is perfect and I would like to incorporate that in the project if possible. Therefore, here's how I would like the message to be structured: ------------------------------------ Incoming Request ------------------------------------ | Date and Time | HTTP Method | Request IP Address | Request URL |
————————————————————————————————————————————————- Or maybe have the layout look like something similar to this:
------------------------------------ Incoming Request ------------------------------------ HTTP Method: req.method Request IP address: req.ip Request URL: req.url
The syntax would be located in fastify.js, unless advised elsewhere, and would look similar to this:
const date = new Date();
const LogData = { // Declare timestamp variable
} Please let me know if you have any recommendations or critiques and I will make sure to adjust my plan accordingly. Thank you again. |
The What do you think? |
Hi @metcoder95, I agree that's a good point thank you for letting me know. Please let me know what you think of my revised version:
const date = new Date();
const LogData = { // Declare timestamp variable const properties = Or perhaps const app = fastify({
const LogData = { const properties = Please let me know if you have any questions. Thank you. |
the code above is not very readable. Go ahead and send a PR but do not alter the current message. |
My apologies I'll make sure to have it more organized moving forward. But Just to make sure would the current message I don't want to alter be:
Thanks. |
As @mcollina pointed out, might be better to see a PR
Yes, if the |
Ok gotcha, I'll make sure to leave that the way it is. Please let me know if you have anymore questions about this and thank you again for all your help. |
Prerequisites
🚀 Feature Proposal
Expose fastify param
createRequestLogMessage
, which would allow customizing request param log message.Motivation
Currently logic for request logging looks like this:
It is not possible to customize it, which may sometimes be desireable.
Example
It would be great to be able to replace
incoming request
with a custom-built message. So something likecreateRequestLogMessage
would default to a function which returns'incoming request'
.Full usage example:
The text was updated successfully, but these errors were encountered: