feat(dev): logging middleware
This commit is contained in:
20
router/middleware/dev.go
Normal file
20
router/middleware/dev.go
Normal file
@@ -0,0 +1,20 @@
|
||||
type LoggerMiddleware struct {
|
||||
log *slog.Logger
|
||||
}
|
||||
|
||||
func NewLoggerMiddleware(l *slog.Logger) *LoggerMiddleware {
|
||||
return &LoggerMiddleware{l}
|
||||
}
|
||||
|
||||
func (l *LoggerMiddleware) Wrap(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
l.log.Debug("Handling request", slog.String("path", r.URL.Path))
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
|
||||
l.log.Debug("Request finished",
|
||||
slog.String("path", r.URL.Path),
|
||||
slog.String("status", w.Header().Get("Status")),
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user