mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-16 03:31:39 +00:00
logpolicy: only log panics when running under systemd
Given that https://github.com/golang/go/issues/42888 is coming, this catches most practical panics without interfering in our development environments. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
24ee0ed3c3
commit
eab80e3877
@ -187,6 +187,10 @@ func runningUnderSystemd() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func redirectStderrToLogPanics() bool {
|
||||||
|
return runningUnderSystemd() || os.Getenv("TS_PLEASE_PANIC") != ""
|
||||||
|
}
|
||||||
|
|
||||||
// tryFixLogStateLocation is a temporary fixup for
|
// tryFixLogStateLocation is a temporary fixup for
|
||||||
// https://github.com/tailscale/tailscale/issues/247 . We accidentally
|
// https://github.com/tailscale/tailscale/issues/247 . We accidentally
|
||||||
// wrote logging state files to /, and then later to $CACHE_DIRECTORY
|
// wrote logging state files to /, and then later to $CACHE_DIRECTORY
|
||||||
@ -436,11 +440,13 @@ func New(collection string) *Policy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filchBuf, filchErr := filch.New(filepath.Join(dir, cmdName), filch.Options{
|
filchBuf, filchErr := filch.New(filepath.Join(dir, cmdName), filch.Options{
|
||||||
ReplaceStderr: true,
|
ReplaceStderr: redirectStderrToLogPanics(),
|
||||||
})
|
})
|
||||||
if filchBuf != nil {
|
if filchBuf != nil {
|
||||||
c.Buffer = filchBuf
|
c.Buffer = filchBuf
|
||||||
c.Stderr = filchBuf.OrigStderr
|
if filchBuf.OrigStderr != nil {
|
||||||
|
c.Stderr = filchBuf.OrigStderr
|
||||||
|
}
|
||||||
}
|
}
|
||||||
lw := logtail.NewLogger(c, log.Printf)
|
lw := logtail.NewLogger(c, log.Printf)
|
||||||
log.SetFlags(0) // other logflags are set on console, not here
|
log.SetFlags(0) // other logflags are set on console, not here
|
||||||
|
Loading…
x
Reference in New Issue
Block a user