From 22da65c215c5b40b3891eabf9a39ddd983bd8f86 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Tue, 15 May 2018 21:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=9B=9E=E8=B0=83=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E4=BC=98=E5=8C=96=EF=BC=8C=E6=94=AF=E6=8C=81=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=9C=A8Rolling=20log=E4=B8=AD=EF=BC=8C=E6=96=B9?= =?UTF-8?q?=E4=BE=BF=E9=97=AE=E9=A2=98=E6=8E=92=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 2 +- .../core/biz/model/HandleCallbackParam.java | 15 ++++++++++++- .../com/xxl/job/core/thread/JobThread.java | 7 +++---- .../core/thread/TriggerCallbackThread.java | 21 +++++++++++++++---- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index e44223ed..75aa019e 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1199,7 +1199,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 8、Window机器下File.separator不兼容问题修复; - 9、任务日志查询速度优化,百万级别日志量搜索速度提升1000倍; - 10、底层LocalCache组件兼容性优化,支持jdk、jdk10编译部署; -- 11、[迭代中]回调log优化,支持展示在rolling log中,方便排查问题; +- 11、任务回调结果优化,支持展示在Rolling log中,方便问题排查; - 12、脚本任务异常Log输出优化; diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/biz/model/HandleCallbackParam.java b/xxl-job-core/src/main/java/com/xxl/job/core/biz/model/HandleCallbackParam.java index 39ec4db1..895aaec4 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/biz/model/HandleCallbackParam.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/biz/model/HandleCallbackParam.java @@ -9,11 +9,14 @@ public class HandleCallbackParam implements Serializable { private static final long serialVersionUID = 42L; private int logId; + private long logDateTim; + private ReturnT executeResult; public HandleCallbackParam(){} - public HandleCallbackParam(int logId, ReturnT executeResult) { + public HandleCallbackParam(int logId, long logDateTim, ReturnT executeResult) { this.logId = logId; + this.logDateTim = logDateTim; this.executeResult = executeResult; } @@ -25,6 +28,14 @@ public class HandleCallbackParam implements Serializable { this.logId = logId; } + public long getLogDateTim() { + return logDateTim; + } + + public void setLogDateTim(long logDateTim) { + this.logDateTim = logDateTim; + } + public ReturnT getExecuteResult() { return executeResult; } @@ -37,7 +48,9 @@ public class HandleCallbackParam implements Serializable { public String toString() { return "HandleCallbackParam{" + "logId=" + logId + + ", logDateTim=" + logDateTim + ", executeResult=" + executeResult + '}'; } + } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java index e6d03967..93b36615 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java @@ -14,7 +14,6 @@ import org.slf4j.LoggerFactory; import java.io.PrintWriter; import java.io.StringWriter; -import java.util.Arrays; import java.util.Date; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; @@ -148,11 +147,11 @@ public class JobThread extends Thread{ // callback handler info if (!toStop) { // commonm - TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), executeResult)); + TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), triggerParam.getLogDateTim(), executeResult)); } else { // is killed ReturnT stopResult = new ReturnT(ReturnT.FAIL_CODE, stopReason + " [业务运行中,被强制终止]"); - TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult)); + TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), triggerParam.getLogDateTim(), stopResult)); } } } @@ -164,7 +163,7 @@ public class JobThread extends Thread{ if (triggerParam!=null) { // is killed ReturnT stopResult = new ReturnT(ReturnT.FAIL_CODE, stopReason + " [任务尚未执行,在调度队列中被终止]"); - TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), stopResult)); + TriggerCallbackThread.pushCallBack(new HandleCallbackParam(triggerParam.getLogId(), triggerParam.getLogDateTim(), stopResult)); } } diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java index 23b56c93..97c3ae4d 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java @@ -4,10 +4,13 @@ import com.xxl.job.core.biz.AdminBiz; import com.xxl.job.core.biz.model.HandleCallbackParam; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.executor.XxlJobExecutor; +import com.xxl.job.core.log.XxlJobFileAppender; +import com.xxl.job.core.log.XxlJobLogger; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; @@ -108,17 +111,27 @@ public class TriggerCallbackThread { try { ReturnT callbackResult = adminBiz.callback(callbackParamList); if (callbackResult!=null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) { - callbackResult = ReturnT.SUCCESS; - logger.info(">>>>>>>>>>> xxl-job callback success, callbackParamList:{}, callbackResult:{}", new Object[]{callbackParamList, callbackResult}); + callbackLog(callbackParamList, "
----------- xxl-job callback success"); break; } else { - logger.info(">>>>>>>>>>> xxl-job callback fail, callbackParamList:{}, callbackResult:{}", new Object[]{callbackParamList, callbackResult}); + callbackLog(callbackParamList, "
----------- xxl-job callback fail, callbackResult:" + callbackResult); } } catch (Exception e) { - logger.error(">>>>>>>>>>> xxl-job callback error, callbackParamList:{}", callbackParamList, e); + callbackLog(callbackParamList, "
----------- xxl-job callback error, errorMsg:" + e.getMessage()); //getInstance().callBackQueue.addAll(callbackParamList); } } } + /** + * callback log + */ + private void callbackLog(List callbackParamList, String logContent){ + for (HandleCallbackParam callbackParam: callbackParamList) { + String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId()); + XxlJobFileAppender.contextHolder.set(logFileName); + XxlJobLogger.log(logContent); + } + } + }