influxdb/server/logger.go

22 lines
477 B
Go

package server
import (
"net/http"
"github.com/influxdata/chronograf"
)
// Logger is middleware that logs the request
func Logger(logger chronograf.Logger, next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
logger.
WithField("component", "server").
WithField("remote_addr", r.RemoteAddr).
WithField("method", r.Method).
WithField("url", r.URL).
Info("Request")
next.ServeHTTP(w, r)
}
return http.HandlerFunc(fn)
}