From 1f94d43b5009cf7f3eb7713e12fc7e1247940bab Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Tue, 27 Apr 2021 09:44:51 -0700 Subject: [PATCH] wgengine/wglog: delay formatting The "stop phrases" we use all occur in wireguard-go in the format string. We can avoid doing a bunch of fmt.Sprintf work when they appear. Signed-off-by: Josh Bleecher Snyder --- wgengine/wglog/wglog.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/wgengine/wglog/wglog.go b/wgengine/wglog/wglog.go index a99ed9c55..c11cb6c4c 100644 --- a/wgengine/wglog/wglog.go +++ b/wgengine/wglog/wglog.go @@ -29,23 +29,22 @@ type Logger struct { // and rewrites peer keys from wireguard-go into Tailscale format. func NewLogger(logf logger.Logf) *Logger { ret := new(Logger) - wrapper := func(format string, args ...interface{}) { - msg := fmt.Sprintf(format, args...) - if strings.Contains(msg, "Routine:") && !strings.Contains(msg, "receive incoming") { + if strings.Contains(format, "Routine:") && !strings.Contains(format, "receive incoming") { // wireguard-go logs as it starts and stops routines. // Drop those; there are a lot of them, and they're just noise. return } - if strings.Contains(msg, "Failed to send data packet") { + if strings.Contains(format, "Failed to send data packet") { // Drop. See https://github.com/tailscale/tailscale/issues/1239. return } - if strings.Contains(msg, "Interface up requested") || strings.Contains(msg, "Interface down requested") { + if strings.Contains(format, "Interface up requested") || strings.Contains(format, "Interface down requested") { // Drop. Logs 1/s constantly while the tun device is open. // See https://github.com/tailscale/tailscale/issues/1388. return } + msg := fmt.Sprintf(format, args...) r := ret.replacer.Load() if r == nil { // No replacements specified; log as originally planned.