2023-03-09 02:35:36 +00:00
|
|
|
package log
|
|
|
|
|
|
|
|
import (
|
2023-05-25 07:06:16 +00:00
|
|
|
"golang.org/x/sys/unix"
|
2023-03-09 02:35:36 +00:00
|
|
|
"os"
|
|
|
|
"runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
var stdErrFileHandler *os.File
|
|
|
|
|
|
|
|
func dupWrite(file *os.File) error {
|
|
|
|
stdErrFileHandler = file
|
2023-05-25 07:06:16 +00:00
|
|
|
if err := unix.Dup2(int(file.Fd()), int(os.Stderr.Fd())); err != nil {
|
2023-03-09 02:35:36 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
runtime.SetFinalizer(stdErrFileHandler, func(fd *os.File) {
|
|
|
|
fd.Close()
|
|
|
|
})
|
|
|
|
return nil
|
|
|
|
}
|