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

Configurable HTTP Response Logging #36

Open
jguttman94 opened this issue Jan 8, 2024 · 0 comments
Open

Configurable HTTP Response Logging #36

jguttman94 opened this issue Jan 8, 2024 · 0 comments

Comments

@jguttman94
Copy link

jguttman94 commented Jan 8, 2024

Currently, the response body will only be logged if the returned status code is >= 400.

https://github.com/go-chi/httplog/blob/master/httplog.go#L90C4-L96C7.
https://github.com/go-chi/httplog/blob/master/httplog.go#L146C3-L149C4.

I have a use case for httplog to act as an audit capability that logs all requests and responses to/from the system. With the current implementation, the response body is only "auditable" if the server processes the request with an error.

My suggestion is to include a new configurable option that would be used for the condition rather than status >= 400. The option can default to the existing logic but allow consumers to define if they want response bodies to be logged in different situations.

if l.Options.ResponseBody {
	body, _ := extra.([]byte)
	responseLog = append(responseLog, slog.Attr{Key: "body", Value: slog.StringValue(string(body))})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant