From 1e4604f60e72f7896b4ae09b07db33c3fef0c93a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 8 Jan 2021 16:47:19 -0800 Subject: [PATCH] wgengine: quiet some wireguard-go logging The log lines that wireguard-go prints as it starts and stops its worker routines are mostly noise. They also happen after other work is completed, which causes failures in some of the log testing packages. Signed-off-by: Josh Bleecher Snyder --- types/logger/logger.go | 13 +++++++++++++ wgengine/userspace.go | 8 +++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/types/logger/logger.go b/types/logger/logger.go index fae6e3dd4..e9a2229fe 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -179,3 +179,16 @@ func (fn ArgWriter) Format(f fmt.State, _ rune) { } var argBufioPool = &sync.Pool{New: func() interface{} { return bufio.NewWriterSize(ioutil.Discard, 1024) }} + +// Filtered returns a Logf that silently swallows some log lines. +// Each inbound format and args is evaluated and printed to a string s. +// The original format and args are passed to logf if and only if allow(s) returns true. +func Filtered(logf Logf, allow func(s string) bool) Logf { + return func(format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + if !allow(msg) { + return + } + logf(format, args...) + } +} diff --git a/wgengine/userspace.go b/wgengine/userspace.go index f7b403ce1..13ddcb981 100644 --- a/wgengine/userspace.go +++ b/wgengine/userspace.go @@ -247,9 +247,15 @@ func newUserspaceEngineAdvanced(conf EngineConfig) (_ Engine, reterr error) { } e.magicConn.SetNetworkUp(e.linkState.AnyInterfaceUp()) + // wireguard-go logs as it starts and stops routines. + // Silence those; there are a lot of them, and they're just noise. + allowLogf := func(s string) bool { + return !strings.HasPrefix(s, "Routine:") + } + filtered := logger.Filtered(logf, allowLogf) // flags==0 because logf is already nested in another logger. // The outer one can display the preferred log prefixes, etc. - dlog := logger.StdLogger(logf) + dlog := logger.StdLogger(filtered) logger := device.Logger{ Debug: dlog, Info: dlog,