MCPcopy
hub / github.com/go-chi/chi / RequestLogger

Function RequestLogger

middleware/logger.go:44–59  ·  middleware/logger.go::RequestLogger

RequestLogger returns a logger handler using a custom LogFormatter.

(f LogFormatter)

Source from the content-addressed store, hash-verified

42
43// RequestLogger returns a logger handler using a custom LogFormatter.
44func RequestLogger(f LogFormatter) func(next http.Handler) http.Handler {
45 return func(next http.Handler) http.Handler {
46 fn := func(w http.ResponseWriter, r *http.Request) {
47 entry := f.NewLogEntry(r)
48 ww := NewWrapResponseWriter(w, r.ProtoMajor)
49
50 t1 := time.Now()
51 defer func() {
52 entry.Write(ww.Status(), ww.BytesWritten(), ww.Header(), time.Since(t1), nil)
53 }()
54
55 next.ServeHTTP(ww, WithLogEntry(r, entry))
56 }
57 return http.HandlerFunc(fn)
58 }
59}
60
61// LogFormatter initiates the beginning of a new LogEntry per request.
62// See DefaultLogFormatter for an example implementation.

Callers 1

initFunction · 0.85

Calls 8

WriteMethod · 0.95
StatusMethod · 0.95
BytesWrittenMethod · 0.95
NewWrapResponseWriterFunction · 0.85
WithLogEntryFunction · 0.85
HandlerFuncMethod · 0.80
NewLogEntryMethod · 0.65
ServeHTTPMethod · 0.45

Tested by

no test coverage detected