MCPcopy Create free account
hub / github.com/rabbitstack/fibratus / redirectStderrToFile

Function redirectStderrToFile

pkg/util/log/logger.go:127–145  ·  view source on GitHub ↗

redirectStderrToFile redirects the standard output stream to a log file. Helpful to capture panics and send them to the file.

(file string)

Source from the content-addressed store, hash-verified

125// redirectStderrToFile redirects the standard output stream to a log file.
126// Helpful to capture panics and send them to the file.
127func 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
147func dupFD(fd uintptr) (windows.Handle, error) {
148 proc := windows.CurrentProcess()

Callers 1

InitFromConfigFunction · 0.85

Calls 2

dupFDFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected