MCPcopy Index your code
hub / github.com/tailscale/tailscale / switchOutputToFile

Method switchOutputToFile

clientupdate/clientupdate_windows.go:282–305  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

280}
281
282func (up *Updater) switchOutputToFile() (io.Closer, error) {
283 var logFilePath string
284 exePath, err := os.Executable()
285 if err != nil {
286 logFilePath = up.startNewLogFile(updaterPrefix, os.Getenv(winVersionEnv))
287 } else {
288 // Use the same suffix as the self-copy executable.
289 suffix := strings.TrimSuffix(strings.TrimPrefix(filepath.Base(exePath), updaterPrefix), ".exe")
290 logFilePath = up.startNewLogFile(updaterPrefix, os.Getenv(winVersionEnv)+suffix)
291 }
292
293 up.Logf("writing update output to: %s", logFilePath)
294 logFile, err := os.Create(logFilePath)
295 if err != nil {
296 return nil, err
297 }
298
299 up.Logf = func(m string, args ...any) {
300 fmt.Fprintf(logFile, m+"\n", args...)
301 }
302 up.Stdout = logFile
303 up.Stderr = logFile
304 return logFile, nil
305}
306
307// startNewLogFile returns a name for a new log file.
308// It cleans up any old log files with the same baseNamePrefix.

Callers 1

updateWindowsMethod · 0.95

Calls 3

startNewLogFileMethod · 0.95
CreateMethod · 0.80
LogfMethod · 0.65

Tested by

no test coverage detected