mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 04:55:31 +00:00
logpolicy: don't create a filch buffer if logging is disabled
Updates #9549 Signed-off-by: Anton Tolchanov <commits@knyar.net>
This commit is contained in:
parent
fb0f8fc0ae
commit
a70287d324
@ -576,13 +576,57 @@ func NewWithConfigPath(collection, dir, cmdName string, netMon *netmon.Monitor,
|
|||||||
if envknob.NoLogsNoSupport() || testenv.InTest() {
|
if envknob.NoLogsNoSupport() || testenv.InTest() {
|
||||||
logf("You have disabled logging. Tailscale will not be able to provide support.")
|
logf("You have disabled logging. Tailscale will not be able to provide support.")
|
||||||
conf.HTTPC = &http.Client{Transport: noopPretendSuccessTransport{}}
|
conf.HTTPC = &http.Client{Transport: noopPretendSuccessTransport{}}
|
||||||
} else if val := getLogTarget(); val != "" {
|
} else {
|
||||||
logf("You have enabled a non-default log target. Doing without being told to by Tailscale staff or your network administrator will make getting support difficult.")
|
// Only attach an on-disk filch buffer if we are going to be sending logs.
|
||||||
conf.BaseURL = val
|
// No reason to persist them locally just to drop them later.
|
||||||
u, _ := url.Parse(val)
|
attachFilchBuffer(&conf, dir, cmdName, logf)
|
||||||
conf.HTTPC = &http.Client{Transport: NewLogtailTransport(u.Host, netMon, health, logf)}
|
|
||||||
|
if val := getLogTarget(); val != "" {
|
||||||
|
logf("You have enabled a non-default log target. Doing without being told to by Tailscale staff or your network administrator will make getting support difficult.")
|
||||||
|
conf.BaseURL = val
|
||||||
|
u, _ := url.Parse(val)
|
||||||
|
conf.HTTPC = &http.Client{Transport: NewLogtailTransport(u.Host, netMon, health, logf)}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
lw := logtail.NewLogger(conf, logf)
|
||||||
|
|
||||||
|
var logOutput io.Writer = lw
|
||||||
|
|
||||||
|
if runtime.GOOS == "windows" && conf.Collection == logtail.CollectionNode {
|
||||||
|
logID := newc.PublicID.String()
|
||||||
|
exe, _ := os.Executable()
|
||||||
|
if strings.EqualFold(filepath.Base(exe), "tailscaled.exe") {
|
||||||
|
diskLogf := filelogger.New("tailscale-service", logID, lw.Logf)
|
||||||
|
logOutput = logger.FuncWriter(diskLogf)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if useStdLogger {
|
||||||
|
log.SetFlags(0) // other log flags are set on console, not here
|
||||||
|
log.SetOutput(logOutput)
|
||||||
|
}
|
||||||
|
|
||||||
|
logf("Program starting: v%v, Go %v: %#v",
|
||||||
|
version.Long(),
|
||||||
|
goVersion(),
|
||||||
|
os.Args)
|
||||||
|
logf("LogID: %v", newc.PublicID)
|
||||||
|
if earlyErrBuf.Len() != 0 {
|
||||||
|
logf("%s", earlyErrBuf.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
return &Policy{
|
||||||
|
Logtail: lw,
|
||||||
|
PublicID: newc.PublicID,
|
||||||
|
Logf: logf,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// attachFilchBuffer creates an on-disk ring buffer using filch and attaches
|
||||||
|
// it to the logtail config. Note that this is optional; if no buffer is set,
|
||||||
|
// logtail will use an in-memory buffer.
|
||||||
|
func attachFilchBuffer(conf *logtail.Config, dir, cmdName string, logf logger.Logf) {
|
||||||
filchOptions := filch.Options{
|
filchOptions := filch.Options{
|
||||||
ReplaceStderr: redirectStderrToLogPanics(),
|
ReplaceStderr: redirectStderrToLogPanics(),
|
||||||
}
|
}
|
||||||
@ -608,41 +652,9 @@ func NewWithConfigPath(collection, dir, cmdName string, netMon *netmon.Monitor,
|
|||||||
conf.Stderr = filchBuf.OrigStderr
|
conf.Stderr = filchBuf.OrigStderr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lw := logtail.NewLogger(conf, logf)
|
|
||||||
|
|
||||||
var logOutput io.Writer = lw
|
|
||||||
|
|
||||||
if runtime.GOOS == "windows" && conf.Collection == logtail.CollectionNode {
|
|
||||||
logID := newc.PublicID.String()
|
|
||||||
exe, _ := os.Executable()
|
|
||||||
if strings.EqualFold(filepath.Base(exe), "tailscaled.exe") {
|
|
||||||
diskLogf := filelogger.New("tailscale-service", logID, lw.Logf)
|
|
||||||
logOutput = logger.FuncWriter(diskLogf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if useStdLogger {
|
|
||||||
log.SetFlags(0) // other log flags are set on console, not here
|
|
||||||
log.SetOutput(logOutput)
|
|
||||||
}
|
|
||||||
|
|
||||||
logf("Program starting: v%v, Go %v: %#v",
|
|
||||||
version.Long(),
|
|
||||||
goVersion(),
|
|
||||||
os.Args)
|
|
||||||
logf("LogID: %v", newc.PublicID)
|
|
||||||
if filchErr != nil {
|
if filchErr != nil {
|
||||||
logf("filch failed: %v", filchErr)
|
logf("filch failed: %v", filchErr)
|
||||||
}
|
}
|
||||||
if earlyErrBuf.Len() != 0 {
|
|
||||||
logf("%s", earlyErrBuf.Bytes())
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Policy{
|
|
||||||
Logtail: lw,
|
|
||||||
PublicID: newc.PublicID,
|
|
||||||
Logf: logf,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dialLog is used by NewLogtailTransport to log the happy path of its
|
// dialLog is used by NewLogtailTransport to log the happy path of its
|
||||||
|
Loading…
Reference in New Issue
Block a user