Skip to content

Commit

Permalink
Merge pull request #3108 from buildkite/ps-200-fix-duplicate-output-d…
Browse files Browse the repository at this point in the history
…ebug

Fix duplicated output when debug is enabled
  • Loading branch information
DrJosh9000 authored Nov 25, 2024
2 parents 1a19080 + ff3bf33 commit 1280e13
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions internal/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,14 +566,18 @@ func (s *Shell) executeCommand(ctx context.Context, cmdCfg process.Config, stdou
}

if s.debug {
// Tee output streams to debug logger.
stdOutStreamer := NewLoggerStreamer(s.Logger)
defer stdOutStreamer.Close()
cmdCfg.Stdout = io.MultiWriter(cmdCfg.Stdout, stdOutStreamer)

stdErrStreamer := NewLoggerStreamer(s.Logger)
defer stdErrStreamer.Close()
cmdCfg.Stderr = io.MultiWriter(cmdCfg.Stderr, stdErrStreamer)
// Display normally-hidden output streams using log streamer.
if cmdCfg.Stdout == io.Discard {
stdOutStreamer := NewLoggerStreamer(s.Logger)
defer stdOutStreamer.Close()
cmdCfg.Stdout = stdOutStreamer
}

if cmdCfg.Stderr == io.Discard {
stdErrStreamer := NewLoggerStreamer(s.Logger)
defer stdErrStreamer.Close()
cmdCfg.Stderr = stdErrStreamer
}
}

if s.commandLog != nil {
Expand Down

0 comments on commit 1280e13

Please sign in to comment.