Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (f *App) Run(args []string) error {
}

log.Infof("bootstrapping with pid %d. Version: %s", os.Getpid(), version.Get())
log.Infof("rendering config flags... %s", cfg.Print())
log.Infof("configuration options: %s", cfg.Print())

// build the filter from the CLI argument. If we got
// a valid expression the filter is attached to the
Expand Down
20 changes: 17 additions & 3 deletions pkg/util/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,30 @@ func InitFromConfig(c Config, filename string) error {
return nil
}

// redirectStderrToFile redirects the standard output stream to a log file.
// Helpful to capture panics and send them to the file.
func redirectStderrToFile(file string) error {
f, err := os.OpenFile(file, os.O_WRONLY|os.O_SYNC|os.O_APPEND, 0644)
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_SYNC|os.O_APPEND, 0644)
if err != nil {
return fmt.Errorf("unable to open %s for stderr redirection: %v", file, err)
}
defer f.Close()
err = windows.SetStdHandle(windows.STD_ERROR_HANDLE, windows.Handle(f.Fd()))

fd, err := dupFD(f.Fd())
if err != nil {
return fmt.Errorf("failed to duplicate file handle: %v", err)
}

err = windows.SetStdHandle(windows.STD_ERROR_HANDLE, fd)
if err != nil {
return fmt.Errorf("failed to redirect stderr to file: %v", err)
}
os.Stderr = f

return nil
}

func dupFD(fd uintptr) (windows.Handle, error) {
proc := windows.CurrentProcess()
var h windows.Handle
return h, windows.DuplicateHandle(proc, windows.Handle(fd), proc, &h, 0, true, windows.DUPLICATE_SAME_ACCESS)
}
Loading