From e3cce6341b5e50903aa951059e2563a6cfe94aeb Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sat, 26 May 2018 13:36:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=84=9A=E6=9C=AC=E4=BB=BB=E5=8A=A1Log?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=B5=81=E5=85=B3=E9=97=AD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 1 + .../java/com/xxl/job/core/util/ScriptUtil.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 6a592c5f..8915746b 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1208,6 +1208,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 11、任务回调结果优化,支持展示在Rolling log中,方便问题排查; - 12、脚本任务异常Log输出优化; - 13、任务线程停止变量修饰符优化; +- 14、脚本任务Log文件流关闭优化; ### TODO LIST diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java b/xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java index 734d50fd..72f61bb7 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java @@ -60,7 +60,10 @@ public class ScriptUtil { // 标准输出:print (null if watchdog timeout) // 错误输出:logging + 异常 (still exists if watchdog timeout) // 标准输入 - try (FileOutputStream fileOutputStream = new FileOutputStream(logFile, true)) { + + FileOutputStream fileOutputStream = null; // + try { + fileOutputStream = new FileOutputStream(logFile, true); PumpStreamHandler streamHandler = new PumpStreamHandler(fileOutputStream, fileOutputStream, null); // command @@ -79,6 +82,15 @@ public class ScriptUtil { } catch (Exception e) { XxlJobLogger.log(e); return -1; + } finally { + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException e) { + XxlJobLogger.log(e); + } + + } } } From df613f163c822f1a6dc6a1a5339d2aae2d7697b5 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Sat, 26 May 2018 13:41:56 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0RM?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xxl/job/core/log/XxlJobFileAppender.java | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java index 0c880968..ff89001a 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java @@ -115,23 +115,21 @@ public class XxlJobFileAppender { appendLog += "\r\n"; // append file content + FileOutputStream fos = null; try { - FileOutputStream fos = null; - try { - fos = new FileOutputStream(logFile, true); - fos.write(appendLog.getBytes("utf-8")); - fos.flush(); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - logger.error(e.getMessage(), e); - } - } - } + fos = new FileOutputStream(logFile, true); + fos.write(appendLog.getBytes("utf-8")); + fos.flush(); } catch (Exception e) { logger.error(e.getMessage(), e); + } finally { + if (fos != null) { + try { + fos.close(); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } } }