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 <mail@eliasnaur.com>
pull/3/head
Elias Naur 5 years ago
parent 334dff897c
commit 943bded910

@ -7,7 +7,6 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"io"
"log" "log"
"path/filepath" "path/filepath"
"reflect" "reflect"
@ -31,7 +30,6 @@ import (
type backend struct { type backend struct {
engine wgengine.Engine engine wgengine.Engine
backend *ipn.LocalBackend backend *ipn.LocalBackend
logger logtail.Logger
devices *multiTUN devices *multiTUN
settings func(*router.Config) error settings func(*router.Config) error
lastCfg *router.Config lastCfg *router.Config
@ -283,6 +281,7 @@ func (b *backend) SetupLogs(logDir string, logID logtail.PrivateID) {
logcfg := logtail.Config{ logcfg := logtail.Config{
Collection: "tailnode.log.tailscale.io", Collection: "tailnode.log.tailscale.io",
PrivateID: logID, PrivateID: logID,
Stderr: log.Writer(),
} }
logcfg.LowMemory = true logcfg.LowMemory = true
drainCh := make(chan struct{}) drainCh := make(chan struct{})
@ -310,13 +309,10 @@ func (b *backend) SetupLogs(logDir string, logID logtail.PrivateID) {
} }
logf := wgengine.RusagePrefixLog(log.Printf) logf := wgengine.RusagePrefixLog(log.Printf)
b.logger = logtail.Log(logcfg, logf) tlog := logtail.Log(logcfg, logf)
log.SetFlags(0) log.SetFlags(0)
log.SetOutput(io.MultiWriter( log.SetOutput(tlog)
log.Writer(),
b.logger,
))
log.Printf("goSetupLogs: success") log.Printf("goSetupLogs: success")

Loading…
Cancel
Save