|
24 | 24 | import java.util.concurrent.Future; |
25 | 25 | import java.util.concurrent.TimeUnit; |
26 | 26 | import java.util.concurrent.TimeoutException; |
| 27 | +import java.util.function.Supplier; |
27 | 28 | import java.util.regex.Matcher; |
28 | 29 | import java.util.regex.Pattern; |
29 | 30 |
|
@@ -303,17 +304,15 @@ private static void logExecutor(int ret, String input, List<String> command, Str |
303 | 304 | * @throws ExecutionException the execution exception |
304 | 305 | */ |
305 | 306 | 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(); |
309 | 308 | ProcessBuilder builder = new ProcessBuilder(); |
310 | 309 | builder.command(commands); |
311 | 310 | dir = dir == null ? new File(System.getProperty("user.dir")) : dir; |
312 | 311 | builder.directory(dir); |
313 | 312 | process = builder.start(); |
314 | 313 | OutputStream outputStream = process.getOutputStream(); |
315 | 314 | if (input != null) { |
316 | | - LOGGER.debug("With stdin {}", input); |
| 315 | + LOGGER.debug("With stdin {}", (Supplier<String>) () -> input); |
317 | 316 | outputStream.write(input.getBytes(Charset.defaultCharset())); |
318 | 317 | } |
319 | 318 | // Close subprocess' stdin |
@@ -363,9 +362,7 @@ public int execute(String input, List<String> commands, Duration timeout, File d |
363 | 362 | * @return the pid |
364 | 363 | */ |
365 | 364 | 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(); |
369 | 366 | ProcessBuilder builder = new ProcessBuilder(); |
370 | 367 | builder.command(commands); |
371 | 368 | dir = dir == null ? new File(System.getProperty("user.dir")) : dir; |
|
0 commit comments