feat(util): enhance logging behavior in ProcessExecutor

- Introduced `AtomicBoolean` to detect error messages dynamically
- Changed logging to use `log.debug` for non-error lines and `log.info` for error-related lines during live updates
- Improved error and output stream handling for better log verbosity and behaviour

Signed-off-by: Balázs Szücs <bszucs1209@gmail.com>
This commit is contained in:
Balázs Szücs 2025-11-15 16:24:12 +01:00
parent be824b126f
commit 557fd1be24

View File

@ -12,6 +12,7 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import io.github.pixee.security.BoundedLineReader;
@ -175,6 +176,7 @@ public class ProcessExecutor {
String messages = "";
int exitCode = 1;
semaphore.acquire();
AtomicBoolean errorDetected = new AtomicBoolean(false);
try {
log.info("Running command: {}", String.join(" ", command));
@ -204,7 +206,16 @@ public class ProcessExecutor {
errorReader, 5_000_000))
!= null) {
errorLines.add(line);
if (liveUpdates) log.info(line);
if (liveUpdates) {
if (line.toUpperCase().contains("ERROR")) {
errorDetected.set(true);
}
if (errorDetected.get()) {
log.info(line);
} else {
log.debug(line);
}
}
}
} catch (InterruptedIOException e) {
log.warn("Error reader thread was interrupted due to timeout.");
@ -227,7 +238,16 @@ public class ProcessExecutor {
outputReader, 5_000_000))
!= null) {
outputLines.add(line);
if (liveUpdates) log.info(line);
if (liveUpdates) {
if (line.toUpperCase().contains("ERROR")) {
errorDetected.set(true);
}
if (errorDetected.get()) {
log.info(line);
} else {
log.debug(line);
}
}
}
} catch (InterruptedIOException e) {
log.warn("Error reader thread was interrupted due to timeout.");