Only log every route if we have VERBOSE enabled
This commit is contained in:
parent
21587493c0
commit
b7d26d5ad7
1 changed files with 17 additions and 15 deletions
32
main.go
32
main.go
|
|
@ -201,21 +201,23 @@ func LoggerMiddleware(logger *zerolog.Logger) func(next http.Handler) http.Handl
|
|||
remote_addr = forwarded_for
|
||||
}
|
||||
// log end request
|
||||
log.Info().
|
||||
//Str("type", "access").
|
||||
Timestamp().
|
||||
Fields(map[string]interface{}{
|
||||
"remote_ip": remote_addr,
|
||||
"url": r.URL.Path,
|
||||
//"proto": r.Proto,
|
||||
"method": r.Method,
|
||||
//"user_agent": r.Header.Get("User-Agent"),
|
||||
"status": ww.Status(),
|
||||
"latency_ms": float64(t2.Sub(t1).Nanoseconds()) / 1000000.0,
|
||||
"bytes_in": r.Header.Get("Content-Length"),
|
||||
"bytes_out": ww.BytesWritten(),
|
||||
}).
|
||||
Msg("incoming_request")
|
||||
if os.Getenv("VERBOSE") != "" {
|
||||
log.Info().
|
||||
//Str("type", "access").
|
||||
Timestamp().
|
||||
Fields(map[string]interface{}{
|
||||
"remote_ip": remote_addr,
|
||||
"url": r.URL.Path,
|
||||
//"proto": r.Proto,
|
||||
"method": r.Method,
|
||||
//"user_agent": r.Header.Get("User-Agent"),
|
||||
"status": ww.Status(),
|
||||
"latency_ms": float64(t2.Sub(t1).Nanoseconds()) / 1000000.0,
|
||||
"bytes_in": r.Header.Get("Content-Length"),
|
||||
"bytes_out": ww.BytesWritten(),
|
||||
}).
|
||||
Msg("incoming_request")
|
||||
}
|
||||
}()
|
||||
|
||||
next.ServeHTTP(ww, r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue