From 1030dd354b56f542a23ea625203d81a75c3ac9d9 Mon Sep 17 00:00:00 2001 From: jaysunxiao Date: Wed, 25 Feb 2026 10:28:55 +0800 Subject: [PATCH] chore[command]: reduce the volume of logs for process command --- .../java/com/zfoo/monitor/util/OSUtils.java | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/monitor/src/main/java/com/zfoo/monitor/util/OSUtils.java b/monitor/src/main/java/com/zfoo/monitor/util/OSUtils.java index 242db05b..78a5d74b 100644 --- a/monitor/src/main/java/com/zfoo/monitor/util/OSUtils.java +++ b/monitor/src/main/java/com/zfoo/monitor/util/OSUtils.java @@ -296,20 +296,20 @@ public abstract class OSUtils { .directory(wd) .start(); - var out = new StringBuilder(); - var err = new StringBuilder(); + var stdout = new StringBuilder(); + var stderr = new StringBuilder(); // 异步读取输出,避免缓冲区阻塞 executors.submit(ThreadUtils.safeRunnable(() -> { try { - out.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream()))); + stdout.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream()))); } catch (IOException e) { throw new RuntimeException(e); } })); executors.submit(ThreadUtils.safeRunnable(() -> { try { - err.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream()))); + stderr.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream()))); } catch (IOException e) { throw new RuntimeException(e); } @@ -326,14 +326,10 @@ public abstract class OSUtils { // 获取线程的退出值,0代表正常退出,非0代表异常中止 int exitValue = process.exitValue(); - if (exitValue != 0) { - logger.error("doExecCommand error executing command exitValue:[{}] result:[{}] err:[{}]", exitValue, err, err); + if (exitValue != 0 || !stderr.isEmpty()) { + logger.error("doExecCommand error executing command exitValue:[{}] stdout:[{}] stderr:[{}]", exitValue, stdout, stderr); } - if (!err.isEmpty()) { - logger.error("doExecCommand error executing command err:[{}]", err); - } - - return out.toString(); + return stdout.toString(); } }