diff --git a/src/main/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManager.java b/src/main/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManager.java index 959d5bf..9cb59f1 100644 --- a/src/main/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManager.java +++ b/src/main/java/com/saucelabs/ci/sauceconnect/AbstractSauceTunnelManager.java @@ -25,6 +25,7 @@ import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; import org.apache.commons.lang3.StringUtils; import org.json.JSONException; import org.slf4j.Logger; @@ -533,6 +534,11 @@ public Process openConnection( final Process process = prepAndCreateProcess( username, apiKey, port, sauceConnectJar, options, printStream, sauceConnectPath); + + // Print sauceconnect process stdout/stderr + new ProcessOutputPrinter(process.getInputStream(), (String x) -> logMessage(printStream, x)).start(); + new ProcessOutputPrinter(process.getErrorStream(), (String x) -> logMessage(printStream, x)).start(); + List openedProcesses = this.openedProcesses.get(name); try { Semaphore semaphore = new Semaphore(1); @@ -544,7 +550,7 @@ public Process openConnection( } else { scMonitor = new SCMonitor("SCMonitor", port, LOGGER); } - + scMonitor.setSemaphore(semaphore); scMonitor.start(); @@ -807,8 +813,30 @@ private void pollEndpoint() { semaphore.release(); } } - + this.LOGGER.trace("No API response yet"); } } + + public class ProcessOutputPrinter extends Thread { + private final InputStream inputStream; + private final Consumer printStream; + + public ProcessOutputPrinter(InputStream inputStream, Consumer printStream) { + this.inputStream = inputStream; + this.printStream = printStream; + } + + @Override + public void run() { + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + printStream.accept(line); + } + } catch (IOException e) { + LOGGER.error("Error reading process output", e); + } + } + } }