HTTP debug middleware should be behind ShouldDebug()
This commit is contained in:
parent
945ddc2403
commit
f7ad97918a
@ -18,6 +18,10 @@ var (
|
|||||||
httpl = logger.DefaultLogger.NewFacility("http", "REST API")
|
httpl = logger.DefaultLogger.NewFacility("http", "REST API")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func shouldDebugHTTP() bool {
|
||||||
|
return l.ShouldDebug("http")
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
l.SetDebug("main", strings.Contains(os.Getenv("STTRACE"), "main") || os.Getenv("STTRACE") == "all")
|
l.SetDebug("main", strings.Contains(os.Getenv("STTRACE"), "main") || os.Getenv("STTRACE") == "all")
|
||||||
l.SetDebug("http", strings.Contains(os.Getenv("STTRACE"), "http") || os.Getenv("STTRACE") == "all")
|
l.SetDebug("http", strings.Contains(os.Getenv("STTRACE"), "http") || os.Getenv("STTRACE") == "all")
|
||||||
|
|||||||
@ -298,6 +298,8 @@ func debugMiddleware(h http.Handler) http.Handler {
|
|||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
t0 := time.Now()
|
t0 := time.Now()
|
||||||
h.ServeHTTP(w, r)
|
h.ServeHTTP(w, r)
|
||||||
|
|
||||||
|
if shouldDebugHTTP() {
|
||||||
ms := 1000 * time.Since(t0).Seconds()
|
ms := 1000 * time.Since(t0).Seconds()
|
||||||
|
|
||||||
// The variable `w` is most likely a *http.response, which we can't do
|
// The variable `w` is most likely a *http.response, which we can't do
|
||||||
@ -313,8 +315,8 @@ func debugMiddleware(h http.Handler) http.Handler {
|
|||||||
written = rf.Int()
|
written = rf.Int()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Debugf("http: %s %q: status %d, %d bytes in %.02f ms", r.Method, r.URL.String(), status, written, ms)
|
l.Debugf("http: %s %q: status %d, %d bytes in %.02f ms", r.Method, r.URL.String(), status, written, ms)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user