github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/logging/dup_unix.go (about)

     1  //go:build !windows
     2  // +build !windows
     3  
     4  package logging
     5  
     6  import (
     7  	"os"
     8  
     9  	"golang.org/x/sys/unix"
    10  )
    11  
    12  // dupToStdOut ensures that anything written to stdout will end up in the given file.
    13  func dupToStdOut(file *os.File) error {
    14  	// https://github.com/golang/go/issues/325
    15  	if err := unix.Dup2(int(file.Fd()), 1); err != nil {
    16  		return err
    17  	}
    18  	os.Stdout = file
    19  	return nil
    20  }
    21  
    22  // dupToStdErr ensures that anything written to stderr will end up in the given file.
    23  func dupToStdErr(file *os.File) error {
    24  	// https://github.com/golang/go/issues/325
    25  	if err := unix.Dup2(int(file.Fd()), 2); err != nil {
    26  		return err
    27  	}
    28  	os.Stderr = file
    29  	return nil
    30  }