From 943bded9108997b47d7b3f4beecae88103cb1189 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sun, 9 Aug 2020 20:19:50 +0200 Subject: [PATCH] cmd/tailscale: don't duplicate log output logtail.Log by default writes log output to stderr, but stderr is taken over by filch's ReplaceStderr, resulting in duplicate logs sent to Tailscale. ReplaceStderr is useful for capturing stack dumps from panics. Configure logtail to route logs to the Android logger, which stops the duplicate logging and replaces an existing MultiWriter setup for the same purpose. Reduce the scope of the logtail logger while here. Fixes tailscale/tailscale#646 Signed-off-by: Elias Naur --- cmd/tailscale/backend.go | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/cmd/tailscale/backend.go b/cmd/tailscale/backend.go index e434713..8624bde 100644 --- a/cmd/tailscale/backend.go +++ b/cmd/tailscale/backend.go @@ -7,7 +7,6 @@ package main import ( "errors" "fmt" - "io" "log" "path/filepath" "reflect" @@ -31,7 +30,6 @@ import ( type backend struct { engine wgengine.Engine backend *ipn.LocalBackend - logger logtail.Logger devices *multiTUN settings func(*router.Config) error lastCfg *router.Config @@ -283,6 +281,7 @@ func (b *backend) SetupLogs(logDir string, logID logtail.PrivateID) { logcfg := logtail.Config{ Collection: "tailnode.log.tailscale.io", PrivateID: logID, + Stderr: log.Writer(), } logcfg.LowMemory = true drainCh := make(chan struct{}) @@ -310,13 +309,10 @@ func (b *backend) SetupLogs(logDir string, logID logtail.PrivateID) { } logf := wgengine.RusagePrefixLog(log.Printf) - b.logger = logtail.Log(logcfg, logf) + tlog := logtail.Log(logcfg, logf) log.SetFlags(0) - log.SetOutput(io.MultiWriter( - log.Writer(), - b.logger, - )) + log.SetOutput(tlog) log.Printf("goSetupLogs: success")