MCPcopy Create free account
hub / github.com/brimdata/super / accessLogMiddleware

Function accessLogMiddleware

service/middleware.go:49–75  ·  view source on GitHub ↗
(logger *zap.Logger)

Source from the content-addressed store, hash-verified

47}
48
49func accessLogMiddleware(logger *zap.Logger) mux.MiddlewareFunc {
50 logger = logger.Named("http.access")
51 return func(next http.Handler) http.Handler {
52 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
53 logger := logger.With(zap.String("request_id", api.RequestIDFromContext(r.Context())))
54 detailedLogger := logger.With(
55 zap.String("host", r.Host),
56 zap.String("method", r.Method),
57 zap.String("proto", r.Proto),
58 zap.String("remote_addr", r.RemoteAddr),
59 zap.Int64("request_content_length", r.ContentLength),
60 zap.Stringer("url", r.URL),
61 )
62 recorder := newRecordingResponseWriter(w)
63 w = recorder
64 detailedLogger.Debug("Request started")
65 defer func(start time.Time) {
66 detailedLogger.Info("Request completed",
67 zap.Duration("elapsed", time.Since(start)),
68 zap.Int("response_content_length", recorder.contentLength),
69 zap.Int("status_code", recorder.statusCode),
70 )
71 }(time.Now())
72 next.ServeHTTP(w, r)
73 })
74 }
75}
76
77func panicCatchMiddleware(logger *zap.Logger) mux.MiddlewareFunc {
78 return func(next http.Handler) http.Handler {

Callers 1

NewCoreFunction · 0.85

Calls 7

RequestIDFromContextFunction · 0.92
ContextMethod · 0.80
DurationMethod · 0.80
ServeHTTPMethod · 0.80
StringMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected