diff options
| author | Aaron Klotz <aaron@tailscale.com> | 2021-12-15 11:43:40 -0700 |
|---|---|---|
| committer | Aaron Klotz <aaron@tailscale.com> | 2021-12-15 13:05:14 -0700 |
| commit | 96188ffd2fb3f14fbe3088603a89c6b283c9e2d8 (patch) | |
| tree | 4c76e937bc77e1de1f3700b9eab9c2adaf0a35c2 /log | |
| parent | 486059589b905719f8bb20c2da36b42ab517c697 (diff) | |
| download | tailscale-aaron/loglog.tar.xz tailscale-aaron/loglog.zip | |
ipn/ipnserver, log/filelogger, logpolicy: when tailscaled is running as a windows service, ensure the service's log messages are written to fileaaron/loglog
This patch moves the Windows-only initialization of the filelogger into logpolicy.
Previously we only did it when babysitting the tailscaled subprocess, but this meant
that log messages from the service itself never made it to disk. This meant that
if logtail could not dial out, its log messages would be lost.
I modified filelogger.New to work a bit differently and added a `maybeWrapForPlatform`
to logpolicy to ensure that the filelogger is plugged in front of logtail ASAP.
Fixes https://github.com/tailscale/tailscale/issues/3570
Signed-off-by: Aaron Klotz <aaron@tailscale.com>
Diffstat (limited to 'log')
| -rw-r--r-- | log/filelogger/log.go | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/log/filelogger/log.go b/log/filelogger/log.go index f8c4da65b..ef3ad1e9f 100644 --- a/log/filelogger/log.go +++ b/log/filelogger/log.go @@ -9,6 +9,7 @@ package filelogger import ( "bytes" "fmt" + "io" "io/ioutil" "log" "os" @@ -26,30 +27,30 @@ const ( maxFiles = 50 ) -// New returns a logf wrapper that appends to local disk log +// New returns a Writer 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 { +func New(fileBasePrefix, logID string, inner *log.Logger) io.Writer { if runtime.GOOS != "windows" { panic("not yet supported on any platform except Windows") } - if logf == nil { - panic("nil logf") + if inner == nil { + panic("nil inner logger") } 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) - return logf + inner.Printf("failed to create local log directory; not writing logs to disk: %v", err) + return inner.Writer() } - logf("local disk logdir: %v", dir) + inner.Printf("local disk logdir: %v", dir) lfw := &logFileWriter{ fileBasePrefix: fileBasePrefix, logID: logID, dir: dir, - wrappedLogf: logf, + wrappedLogf: inner.Printf, } - return lfw.Logf + return logger.FuncWriter(lfw.Logf) } // logFileWriter is the state for the log writer & rotator. |
