parent
1e2e3c1362
commit
43ee0e4baf
|
@ -2,6 +2,7 @@ package server
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/influxdata/chronograf"
|
||||
)
|
||||
|
@ -9,6 +10,7 @@ import (
|
|||
// 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) {
|
||||
now := time.Now()
|
||||
logger.
|
||||
WithField("component", "server").
|
||||
WithField("remote_addr", r.RemoteAddr).
|
||||
|
@ -16,6 +18,14 @@ func Logger(logger chronograf.Logger, next http.Handler) http.Handler {
|
|||
WithField("url", r.URL).
|
||||
Info("Request")
|
||||
next.ServeHTTP(w, r)
|
||||
later := time.Now()
|
||||
elapsed := later.Sub(now)
|
||||
|
||||
logger.
|
||||
WithField("component", "server").
|
||||
WithField("remote_addr", r.RemoteAddr).
|
||||
WithField("response_time", elapsed.String()).
|
||||
Info("Success")
|
||||
}
|
||||
return http.HandlerFunc(fn)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue