MCPcopy Index your code
hub / github.com/dreamsofcode-io/zenstats / logging

Function logging

internal/middleware/logging.go:19–37  ·  view source on GitHub ↗
(logger *slog.Logger, next http.Handler)

Source from the content-addressed store, hash-verified

17}
18
19func logging(logger *slog.Logger, next http.Handler) http.Handler {
20 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
21 wrapped := &wrappedResponseWriter{
22 ResponseWriter: w,
23 }
24
25 start := time.Now()
26 next.ServeHTTP(wrapped, r)
27 duration := time.Since(start)
28
29 logger.Info(
30 "handled request",
31 slog.String("method", r.Method),
32 slog.String("path", r.URL.Path),
33 slog.Int64("duration_ns", duration.Nanoseconds()),
34 slog.Int("status", wrapped.statusCode),
35 )
36 })
37}
38
39// Logging middleware is used to write log information out to the console
40// on each request/response.

Callers 1

LoggingFunction · 0.85

Calls 1

ServeHTTPMethod · 0.80

Tested by

no test coverage detected