cmd/derper, types/logger: move log filter to shared package
So we can use it in trunkd to quiet down the logs there. Updates #5563 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Ie3177dc33f5ad103db832aab5a3e0e4f128f973f
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
|
||||
"context"
|
||||
|
||||
"go4.org/mem"
|
||||
"tailscale.com/envknob"
|
||||
"tailscale.com/util/ctxkey"
|
||||
)
|
||||
@@ -393,3 +394,25 @@ func TestLogger(tb TBLogger) Logf {
|
||||
tb.Logf(" ... "+format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
// HTTPServerLogFilter is an io.Writer that can be used as the
|
||||
// net/http.Server.ErrorLog logger, and will filter out noisy, low-signal
|
||||
// messages that clutter up logs.
|
||||
type HTTPServerLogFilter struct {
|
||||
Inner Logf
|
||||
}
|
||||
|
||||
func (lf HTTPServerLogFilter) Write(p []byte) (int, error) {
|
||||
b := mem.B(p)
|
||||
if mem.HasSuffix(b, mem.S(": EOF\n")) ||
|
||||
mem.HasSuffix(b, mem.S(": i/o timeout\n")) ||
|
||||
mem.HasSuffix(b, mem.S(": read: connection reset by peer\n")) ||
|
||||
mem.HasSuffix(b, mem.S(": remote error: tls: bad certificate\n")) ||
|
||||
mem.HasSuffix(b, mem.S(": tls: first record does not look like a TLS handshake\n")) {
|
||||
// Skip this log message, but say that we processed it
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
lf.Inner("%s", p)
|
||||
return len(p), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user