tsweb: add HandlerOptions.Quiet499s

Client termination of a request is a fairly common situation
where we may want to suppress logs for.
The Quiet499s suppresses such logs similar to Quiet200s.

Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
Joe Tsai 2022-08-01 15:25:56 -07:00
parent 357fd85ecf
commit bc9d4ac8ea

View File

@ -186,6 +186,7 @@ type ReturnHandler interface {
type HandlerOptions struct {
Quiet200s bool // if set, do not log successfully handled HTTP requests
Quiet499s bool // if set, do not log client-canceled HTTP requests
Logf logger.Logf
Now func() time.Time // if nil, defaults to time.Now
@ -310,7 +311,10 @@ func (h retHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}
if msg.Code != 200 || !h.opts.Quiet200s {
switch {
case msg.Code == 200 && h.opts.Quiet200s:
case msg.Code == 499 && h.opts.Quiet499s:
default:
h.opts.Logf("%s", msg)
}