From 953f560e9855fd2fbdeb7b1983c1b5db69ed54c1 Mon Sep 17 00:00:00 2001 From: Hayden Young Date: Sun, 21 Mar 2021 20:55:54 +0000 Subject: [PATCH] feat: hide logs behind ENV!=production --- middlewares/log.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/middlewares/log.go b/middlewares/log.go index d3fbb4e..9b2ad3a 100644 --- a/middlewares/log.go +++ b/middlewares/log.go @@ -3,14 +3,19 @@ package middlewares import ( "log" "net/http" + "os" "time" ) func LogMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - now := time.Now() - next.ServeHTTP(w, r) - since := time.Since(now).Milliseconds - log.Printf("%v %v -- %v", r.Method, r.URL.Path, since()) + if os.Getenv("ENV") != "production" { + now := time.Now() + next.ServeHTTP(w, r) + since := time.Since(now).Milliseconds + log.Printf("%v %v -- %v", r.Method, r.URL.Path, since()) + } else { + next.ServeHTTP(w, r) + } }) }