Skip to content

Commit 4b336e4

Browse files
committed
Avoid conditional for single-logs
Signed-off-by: Robert Young <robertyoungnz@gmail.com>
1 parent 0ea1d80 commit 4b336e4

1 file changed

Lines changed: 4 additions & 7 deletions

File tree

  • kroxylicious-systemtests/src/main/java/io/kroxylicious/systemtests/executor

kroxylicious-systemtests/src/main/java/io/kroxylicious/systemtests/executor/Exec.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.concurrent.Future;
2525
import java.util.concurrent.TimeUnit;
2626
import java.util.concurrent.TimeoutException;
27+
import java.util.function.Supplier;
2728
import java.util.regex.Matcher;
2829
import java.util.regex.Pattern;
2930

@@ -303,17 +304,15 @@ private static void logExecutor(int ret, String input, List<String> command, Str
303304
* @throws ExecutionException the execution exception
304305
*/
305306
public int execute(String input, List<String> commands, Duration timeout, File dir) throws IOException, InterruptedException, ExecutionException {
306-
if (LOGGER.isDebugEnabled()) {
307-
LOGGER.debug("Running command - {}", String.join(" ", commands.toArray(new String[0])));
308-
}
307+
LOGGER.atDebug().setMessage("Running command - {}").addArgument(() -> String.join(" ", commands.toArray(new String[0]))).log();
309308
ProcessBuilder builder = new ProcessBuilder();
310309
builder.command(commands);
311310
dir = dir == null ? new File(System.getProperty("user.dir")) : dir;
312311
builder.directory(dir);
313312
process = builder.start();
314313
OutputStream outputStream = process.getOutputStream();
315314
if (input != null) {
316-
LOGGER.debug("With stdin {}", input);
315+
LOGGER.debug("With stdin {}", (Supplier<String>) () -> input);
317316
outputStream.write(input.getBytes(Charset.defaultCharset()));
318317
}
319318
// Close subprocess' stdin
@@ -363,9 +362,7 @@ public int execute(String input, List<String> commands, Duration timeout, File d
363362
* @return the pid
364363
*/
365364
public long executeWithoutWait(String input, List<String> commands, File dir) {
366-
if (LOGGER.isDebugEnabled()) {
367-
LOGGER.debug("Running command - {}", String.join(" ", commands.toArray(new String[0])));
368-
}
365+
LOGGER.atDebug().setMessage("Running command - {}").addArgument(() -> String.join(" ", commands.toArray(new String[0]))).log();
369366
ProcessBuilder builder = new ProcessBuilder();
370367
builder.command(commands);
371368
dir = dir == null ? new File(System.getProperty("user.dir")) : dir;

0 commit comments

Comments
 (0)