Skip to content
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

🚀 Log request headers in logger middleware #1532

Closed
mckingho opened this issue Sep 16, 2021 · 5 comments · Fixed by #1678
Closed

🚀 Log request headers in logger middleware #1532

mckingho opened this issue Sep 16, 2021 · 5 comments · Fixed by #1678

Comments

@mckingho
Copy link

mckingho commented Sep 16, 2021

Is your feature request related to a problem?
Yes. I want to log whole request headers using logger middleware.

Describe the solution you'd like
A new template tag could be added and support the feature logging all request headers.

const (
    TagReqHeaders = "reqHeaders"
)

Additional context
According to #1148, I can only get all headers using fasthttp's functions. Maybe it is also good to add a function for fiber context.

@welcome
Copy link

welcome bot commented Sep 16, 2021

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@shytikov
Copy link

I think that makes sense if the default logging format would be JSON, not plain text as it is right now. Frankly, I don't know how to implement that in a readable manner in plain text, or how to enforce the JSON in the current implementation...

Am I wrong about that?

@mckingho
Copy link
Author

I think there is no standard for logging format, but I prefer single-line json string for request logging.
Here is a snippet in my workaround:

headers := make(map[string]string)
c.Request().Header.VisitAll(func(k, v []byte) {
	headers[string(k)] = string(v)
})
headersBuffer, _ := json.Marshal(headers)
_ = c.Locals("headers", headersBuffer)

@etloreq
Copy link

etloreq commented Oct 1, 2021

What about the Authorization header and maybe some other secret data? There should be a way to specify secret headers that should not be logged

@c1moore
Copy link

c1moore commented Oct 16, 2021

Is this still applicable? Looks like there's already a TagReqHeaders tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants