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 <josharian@gmail.com>
pull/1829/head
Josh Bleecher Snyder 3 years ago
parent 544d8d0ab8
commit 1f94d43b50

@ -29,23 +29,22 @@ type Logger struct {
// and rewrites peer keys from wireguard-go into Tailscale format. // and rewrites peer keys from wireguard-go into Tailscale format.
func NewLogger(logf logger.Logf) *Logger { func NewLogger(logf logger.Logf) *Logger {
ret := new(Logger) ret := new(Logger)
wrapper := func(format string, args ...interface{}) { wrapper := func(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...) if strings.Contains(format, "Routine:") && !strings.Contains(format, "receive incoming") {
if strings.Contains(msg, "Routine:") && !strings.Contains(msg, "receive incoming") {
// wireguard-go logs as it starts and stops routines. // wireguard-go logs as it starts and stops routines.
// Drop those; there are a lot of them, and they're just noise. // Drop those; there are a lot of them, and they're just noise.
return 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. // Drop. See https://github.com/tailscale/tailscale/issues/1239.
return 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. // Drop. Logs 1/s constantly while the tun device is open.
// See https://github.com/tailscale/tailscale/issues/1388. // See https://github.com/tailscale/tailscale/issues/1388.
return return
} }
msg := fmt.Sprintf(format, args...)
r := ret.replacer.Load() r := ret.replacer.Load()
if r == nil { if r == nil {
// No replacements specified; log as originally planned. // No replacements specified; log as originally planned.

Loading…
Cancel
Save