Skip to content

Commit 1030dd3

Browse files
committed
chore[command]: reduce the volume of logs for process command
1 parent 2d31c2a commit 1030dd3

1 file changed

Lines changed: 7 additions & 11 deletions

File tree

monitor/src/main/java/com/zfoo/monitor/util/OSUtils.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -296,20 +296,20 @@ private static String doExecCommand(String command, File wd) throws IOException,
296296
.directory(wd)
297297
.start();
298298

299-
var out = new StringBuilder();
300-
var err = new StringBuilder();
299+
var stdout = new StringBuilder();
300+
var stderr = new StringBuilder();
301301

302302
// 异步读取输出,避免缓冲区阻塞
303303
executors.submit(ThreadUtils.safeRunnable(() -> {
304304
try {
305-
out.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream())));
305+
stdout.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getInputStream())));
306306
} catch (IOException e) {
307307
throw new RuntimeException(e);
308308
}
309309
}));
310310
executors.submit(ThreadUtils.safeRunnable(() -> {
311311
try {
312-
err.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream())));
312+
stderr.append(StringUtils.bytesToString(IOUtils.toByteArray(process.getErrorStream())));
313313
} catch (IOException e) {
314314
throw new RuntimeException(e);
315315
}
@@ -326,14 +326,10 @@ private static String doExecCommand(String command, File wd) throws IOException,
326326

327327
// 获取线程的退出值,0代表正常退出,非0代表异常中止
328328
int exitValue = process.exitValue();
329-
if (exitValue != 0) {
330-
logger.error("doExecCommand error executing command exitValue:[{}] result:[{}] err:[{}]", exitValue, err, err);
329+
if (exitValue != 0 || !stderr.isEmpty()) {
330+
logger.error("doExecCommand error executing command exitValue:[{}] stdout:[{}] stderr:[{}]", exitValue, stdout, stderr);
331331
}
332332

333-
if (!err.isEmpty()) {
334-
logger.error("doExecCommand error executing command err:[{}]", err);
335-
}
336-
337-
return out.toString();
333+
return stdout.toString();
338334
}
339335
}

0 commit comments

Comments
 (0)