mirror of
https://github.com/stefanprodan/podinfo.git
synced 2026-02-28 17:10:19 +00:00
32 lines
633 B
Go
32 lines
633 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
type LoggingMiddleware struct {
|
|
logger *zap.Logger
|
|
}
|
|
|
|
func NewLoggingMiddleware(logger *zap.Logger) *LoggingMiddleware {
|
|
return &LoggingMiddleware{
|
|
logger: logger,
|
|
}
|
|
}
|
|
|
|
func (m *LoggingMiddleware) Handler(next http.Handler) http.Handler {
|
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
m.logger.Debug(
|
|
"request started",
|
|
zap.String("proto", r.Proto),
|
|
zap.String("uri", r.RequestURI),
|
|
zap.String("method", r.Method),
|
|
zap.String("remote", r.RemoteAddr),
|
|
zap.String("user-agent", r.UserAgent()),
|
|
)
|
|
next.ServeHTTP(w, r)
|
|
})
|
|
}
|