MCPcopy Index your code
hub / github.com/dnote/dnote / Logging

Function Logging

pkg/server/middleware/logging.go:40–57  ·  view source on GitHub ↗

logging is a logging middleware

(inner http.Handler)

Source from the content-addressed store, hash-verified

38
39// logging is a logging middleware
40func Logging(inner http.Handler) http.HandlerFunc {
41 return func(w http.ResponseWriter, r *http.Request) {
42 start := time.Now()
43
44 lw := logResponseWriter{w, http.StatusOK}
45 inner.ServeHTTP(&lw, r)
46
47 log.WithFields(log.Fields{
48 "origin": r.Header.Get("Origin"),
49 "remoteAddr": lookupIP(r),
50 "uri": r.RequestURI,
51 "statusCode": lw.statusCode,
52 "method": r.Method,
53 "duration": fmt.Sprintf("%dms", time.Since(start)/1000000),
54 "userAgent": r.Header.Get("User-Agent"),
55 }).Info("incoming request")
56 }
57}

Callers 1

GlobalFunction · 0.85

Calls 5

WithFieldsFunction · 0.92
lookupIPFunction · 0.85
ServeHTTPMethod · 0.80
InfoMethod · 0.80
NowMethod · 0.65

Tested by

no test coverage detected