redirectStderrToFile redirects the standard output stream to a log file. Helpful to capture panics and send them to the file.
(file string)
| 125 | // redirectStderrToFile redirects the standard output stream to a log file. |
| 126 | // Helpful to capture panics and send them to the file. |
| 127 | func redirectStderrToFile(file string) error { |
| 128 | f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644) |
| 129 | if err != nil { |
| 130 | return fmt.Errorf("unable to open %s for stderr redirection: %v", file, err) |
| 131 | } |
| 132 | defer f.Close() |
| 133 | |
| 134 | fd, err := dupFD(f.Fd()) |
| 135 | if err != nil { |
| 136 | return fmt.Errorf("failed to duplicate file handle: %v", err) |
| 137 | } |
| 138 | |
| 139 | err = windows.SetStdHandle(windows.STD_ERROR_HANDLE, fd) |
| 140 | if err != nil { |
| 141 | return fmt.Errorf("failed to redirect stderr to file: %v", err) |
| 142 | } |
| 143 | |
| 144 | return nil |
| 145 | } |
| 146 | |
| 147 | func dupFD(fd uintptr) (windows.Handle, error) { |
| 148 | proc := windows.CurrentProcess() |
no test coverage detected