MCPcopy Create free account
hub / github.com/goadesign/goa / log

Function log

http/middleware/log.go:55–73  ·  view source on GitHub ↗

log does the actual logging given the logger.

(l middleware.Logger, r *http.Request, w http.ResponseWriter, next http.Handler)

Source from the content-addressed store, hash-verified

53
54// log does the actual logging given the logger.
55func 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.
76func from(req *http.Request) string {

Callers 2

LogFunction · 0.85
LogContextFunction · 0.85

Calls 7

fromFunction · 0.85
CaptureResponseFunction · 0.85
ContextMethod · 0.80
shortIDFunction · 0.70
LogMethod · 0.65
StringMethod · 0.65
ServeHTTPMethod · 0.65

Tested by

no test coverage detected