feat: hide logs behind ENV!=production
Cette révision appartient à :
Parent
5cd05ba871
révision
953f560e98
1 fichiers modifiés avec 9 ajouts et 4 suppressions
|
@ -3,14 +3,19 @@ package middlewares
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func LogMiddleware(next http.Handler) http.Handler {
|
func LogMiddleware(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
now := time.Now()
|
if os.Getenv("ENV") != "production" {
|
||||||
next.ServeHTTP(w, r)
|
now := time.Now()
|
||||||
since := time.Since(now).Milliseconds
|
next.ServeHTTP(w, r)
|
||||||
log.Printf("%v %v -- %v", r.Method, r.URL.Path, since())
|
since := time.Since(now).Milliseconds
|
||||||
|
log.Printf("%v %v -- %v", r.Method, r.URL.Path, since())
|
||||||
|
} else {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Référencer dans un nouveau ticket