log does the actual logging given the logger.
(l middleware.Logger, r *http.Request, w http.ResponseWriter, next http.Handler)
| 53 | |
| 54 | // log does the actual logging given the logger. |
| 55 | func log(l middleware.Logger, r *http.Request, w http.ResponseWriter, next http.Handler) { |
| 56 | reqID := r.Context().Value(middleware.RequestIDKey) |
| 57 | if reqID == nil { |
| 58 | reqID = shortID() |
| 59 | } |
| 60 | started := time.Now() |
| 61 | |
| 62 | l.Log("id", reqID, // nolint: errcheck |
| 63 | "req", r.Method+" "+r.URL.String(), |
| 64 | "from", from(r)) |
| 65 | |
| 66 | rw := CaptureResponse(w) |
| 67 | next.ServeHTTP(rw, r) |
| 68 | |
| 69 | l.Log("id", reqID, // nolint: errcheck |
| 70 | "status", rw.StatusCode, |
| 71 | "bytes", rw.ContentLength, |
| 72 | "time", time.Since(started).String()) |
| 73 | } |
| 74 | |
| 75 | // from makes a best effort to compute the request client IP. |
| 76 | func from(req *http.Request) string { |