-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add back in HTTP logging to what was present in v3, to each of the handlers. Signed-off-by: mcoops <cooper.d.mark@gmail.com>
- Loading branch information
Showing
2 changed files
with
45 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package httptransport | ||
|
||
import ( | ||
"net/http" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/rs/zerolog" | ||
) | ||
|
||
type httpStatusWriter struct { | ||
http.ResponseWriter | ||
|
||
StatusCode int | ||
} | ||
|
||
// LoggingHandler will log HTTP requests using the pre initialized zerolog. | ||
func LoggingHandler(next http.Handler) http.HandlerFunc { | ||
return func(w http.ResponseWriter, r *http.Request) { | ||
start := time.Now() | ||
|
||
log := zerolog.Ctx(r.Context()) | ||
|
||
next.ServeHTTP(w, r) | ||
|
||
log.Info(). | ||
Str("remote addr", r.RemoteAddr). | ||
Str("method", r.Method). | ||
Str("request uri", r.RequestURI). | ||
Str("status", strconv.Itoa(http.StatusOK)). | ||
Float64("elapsed time (md)", float64(time.Since(start).Nanoseconds())*1e-6). | ||
Msg("handled HTTP request") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters