From c66e15772f884cc211e0ad064ce966b4a1576a76 Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Fri, 23 Sep 2022 10:19:13 -0700 Subject: [PATCH] tsweb: consider 304s as successful for quiet logging Static resource handlers will generate lots of 304s, which are effectively successful responses. Signed-off-by: Mihai Parparita --- tsweb/tsweb.go | 8 ++++---- tsweb/tsweb_test.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index 5ce65680f..b48a5531b 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -185,9 +185,9 @@ type ReturnHandler interface { } type HandlerOptions struct { - Quiet200s bool // if set, do not log successfully handled HTTP requests - Logf logger.Logf - Now func() time.Time // if nil, defaults to time.Now + QuietLoggingIfSuccessful bool // if set, do not log successfully handled HTTP requests (200 and 304 status codes) + Logf logger.Logf + Now func() time.Time // if nil, defaults to time.Now // If non-nil, StatusCodeCounters maintains counters // of status codes for handled responses. @@ -317,7 +317,7 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } - if msg.Code != 200 || !h.opts.Quiet200s { + if !h.opts.QuietLoggingIfSuccessful || (msg.Code != http.StatusOK && msg.Code != http.StatusNotModified) { h.opts.Logf("%s", msg) } diff --git a/tsweb/tsweb_test.go b/tsweb/tsweb_test.go index 2de762a96..634486e15 100644 --- a/tsweb/tsweb_test.go +++ b/tsweb/tsweb_test.go @@ -303,7 +303,7 @@ func BenchmarkLogNot200(b *testing.B) { // Implicit 200 OK. return nil }) - h := StdHandler(rh, HandlerOptions{Quiet200s: true}) + h := StdHandler(rh, HandlerOptions{QuietLoggingIfSuccessful: true}) req := httptest.NewRequest("GET", "/", nil) rw := new(httptest.ResponseRecorder) for i := 0; i < b.N; i++ {