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

Extend logging middleware to optionally only log failed HTTP requests #1909

Merged
merged 3 commits into from
Oct 8, 2016

Conversation

tomwilkie
Copy link
Contributor

No description provided.

Copy link
Contributor

@ekimekim ekimekim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit, not required

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
begin := time.Now()
uri := r.RequestURI // capture the URI before running next, as it may get rewritten
i := &interceptor{ResponseWriter: w, statusCode: http.StatusOK}
next.ServeHTTP(i, r)
log.Infof("%s %s (%d) %s", r.Method, uri, i.statusCode, time.Since(begin))
if l.LogSuccess || !(200 <= i.statusCode && i.statusCode < 300) {

This comment was marked as abuse.

This comment was marked as abuse.

@tomwilkie tomwilkie merged commit 727404c into master Oct 8, 2016
@tomwilkie tomwilkie deleted the only-log-failed-queries branch October 8, 2016 01:03
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

Successfully merging this pull request may close these issues.

2 participants