Skip to content

Commit

Permalink
Option to redirect devserver stdout/stderr to a file (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
tebeka authored May 1, 2024
1 parent fe44a47 commit d051de6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
10 changes: 10 additions & 0 deletions testsuite/devserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type DevServerOptions struct {
LogLevel string
// Additional arguments to the dev server.
ExtraArgs []string
// Where to redirect stdout and stderr, if nil they will be redirected to the current process.
Stdout io.Writer
Stderr io.Writer
}

// Temporal CLI based DevServer
Expand Down Expand Up @@ -111,6 +114,13 @@ func StartDevServer(ctx context.Context, options DevServerOptions) (*DevServer,
args := prepareCommand(&options, host, port, clientOptions.Namespace)

cmd := newCmd(exePath, args...)
if options.Stdout != nil {
cmd.Stdout = options.Stdout
}
if options.Stderr != nil {
cmd.Stderr = options.Stderr
}

clientOptions.Logger.Info("Starting DevServer", "ExePath", exePath, "Args", args)
if err := cmd.Start(); err != nil {
return nil, fmt.Errorf("failed starting: %w", err)
Expand Down
3 changes: 2 additions & 1 deletion testsuite/process_nonwindows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import (
// newCmd creates a new command with the given executable path and arguments.
func newCmd(exePath string, args ...string) *exec.Cmd {
cmd := exec.Command(exePath, args...)
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd
}

Expand Down
4 changes: 3 additions & 1 deletion testsuite/process_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ func newCmd(exePath string, args ...string) *exec.Cmd {
// isolate the process and signals sent to it from the current console
CreationFlags: syscall.CREATE_NEW_PROCESS_GROUP,
}
cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

return cmd
}

Expand Down

0 comments on commit d051de6

Please sign in to comment.