diff --git a/logpolicy/logpolicy.go b/logpolicy/logpolicy.go index d6f78cbd7..f7f552cda 100644 --- a/logpolicy/logpolicy.go +++ b/logpolicy/logpolicy.go @@ -128,6 +128,13 @@ func (l logWriter) Write(buf []byte) (int, error) { // logsDir returns the directory to use for log configuration and // buffer storage. func logsDir(logf logger.Logf) string { + if d := os.Getenv("TS_LOGS_DIR"); d != "" { + fi, err := os.Stat(d) + if err == nil && fi.IsDir() { + return d + } + } + // STATE_DIRECTORY is set by systemd 240+ but we support older // systems-d. For example, Ubuntu 18.04 (Bionic Beaver) is 237. systemdStateDir := os.Getenv("STATE_DIRECTORY") diff --git a/tstest/integration/integration_test.go b/tstest/integration/integration_test.go index 8d5c0a71a..eaa1fb29e 100644 --- a/tstest/integration/integration_test.go +++ b/tstest/integration/integration_test.go @@ -639,6 +639,7 @@ func (n *testNode) StartDaemonAsIPNGOOS(t testing.TB, ipnGOOS string) *Daemon { "HTTP_PROXY="+n.env.TrafficTrapServer.URL, "HTTPS_PROXY="+n.env.TrafficTrapServer.URL, "TS_DEBUG_TAILSCALED_IPN_GOOS="+ipnGOOS, + "TS_LOGS_DIR="+t.TempDir(), ) cmd.Stderr = &nodeOutputParser{n: n} if *verboseTailscaled { @@ -753,6 +754,7 @@ func (n *testNode) Tailscale(arg ...string) *exec.Cmd { cmd.Dir = n.dir cmd.Env = append(os.Environ(), "TS_DEBUG_UP_FLAG_GOOS="+n.upFlagGOOS, + "TS_LOGS_DIR="+n.env.t.TempDir(), ) if *verboseTailscale { cmd.Stdout = os.Stdout