diff --git a/log/filelogger/log.go b/log/filelogger/log.go index a9ce48555..890617bee 100644 --- a/log/filelogger/log.go +++ b/log/filelogger/log.go @@ -25,17 +25,17 @@ const ( maxFiles = 50 ) -// New returns a logf wrapper that appends to local disk log -// files on Windows, rotating old log files as needed to stay under -// file count & byte limits. -func New(fileBasePrefix, logID string, logf logger.Logf) logger.Logf { +// New returns a logf wrapper that appends to local disk log files in dir on +// Windows, creating dir if needed and rotating old log files as needed to +// stay under file count & byte limits. If dir can't be created, it logs +// that and returns logf unchanged. +func New(dir, fileBasePrefix, logID string, logf logger.Logf) logger.Logf { if runtime.GOOS != "windows" { panic("not yet supported on any platform except Windows") } if logf == nil { panic("nil logf") } - dir := filepath.Join(os.Getenv("ProgramData"), "Tailscale", "Logs") if err := os.MkdirAll(dir, 0700); err != nil { log.Printf("failed to create local log directory; not writing logs to disk: %v", err) diff --git a/logpolicy/logpolicy.go b/logpolicy/logpolicy.go index 78b3ccc13..ac40ce56f 100644 --- a/logpolicy/logpolicy.go +++ b/logpolicy/logpolicy.go @@ -687,7 +687,10 @@ func (opts Options) init(disableLogging bool) (*logtail.Config, *Policy) { logID := newc.PublicID.String() exe, _ := os.Executable() if strings.EqualFold(filepath.Base(exe), "tailscaled.exe") { - diskLogf := filelogger.New("tailscale-service", logID, lw.Logf) + // Alongside the log config: %ProgramData%\Tailscale\Logs for + // the service, or %LocalAppData%\Tailscale\Logs for a tailscaled + // run by a regular user. See LogsDir. + diskLogf := filelogger.New(filepath.Join(opts.Dir, "Logs"), "tailscale-service", logID, lw.Logf) logOutput = logger.FuncWriter(diskLogf) } }