MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / Logging

Function Logging

pkg/middlewares/http/logging.go:33–48  ·  view source on GitHub ↗

simple logging for http requests

(logger log.Logger, next nhttp.Handler)

Source from the content-addressed store, hash-verified

31
32// simple logging for http requests
33func Logging(logger log.Logger, next nhttp.Handler) nhttp.Handler {
34 return nhttp.HandlerFunc(func(w http.ResponseWriter, r *nhttp.Request) {
35 startTime := time.Now()
36
37 // Create a response writer that captures the status code
38 lrw := &loggingResponseWriter{ResponseWriter: w}
39 next.ServeHTTP(lrw, r)
40
41 _ = logger.Log(log.LevelInfo,
42 "uri", r.RequestURI,
43 "code", lrw.statusCode,
44 "method", r.Method,
45 "duration", time.Since(startTime).Seconds(),
46 )
47 })
48}
49
50// WriteHeader captures the status code
51func (lrw *loggingResponseWriter) WriteHeader(code int) {

Callers

nothing calls this directly

Calls 1

ServeHTTPMethod · 0.45

Tested by

no test coverage detected