From 5e39a9547812c310725b86e9cbe725648a7d502c Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Tue, 19 Dec 2017 21:26:30 +0800 Subject: [PATCH] =?UTF-8?q?Log=E7=BB=84=E4=BB=B6=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=BE=93=E5=87=BA=E5=BC=82=E5=B8=B8=E6=A0=88=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/XXL-JOB官方文档.md | 3 ++- .../java/com/xxl/job/core/log/XxlJobLogger.java | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index f65b33ba..717e2991 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1064,6 +1064,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 10、执行器端口支持随机生成(小于等于0时),避免端口定义冲突; - 11、任务Cron长度扩展支持至128位; - 12、调度报表优化,支持时间区间筛选; +- 13、Log组件支持输出异常栈信息; ### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; @@ -1085,7 +1086,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 17、JobHandler提供 init/destroy 方法,支持自定义任务线程销毁逻辑; - 18、执行器回调地址/日志地址格式兼容,是否已"/"结尾均支持; - 19、失败重试完整支持:任务流程分为触发和执行,目前仅支持触发失败的重试;后续支持任务执行失败的重试,通过任务返回值判断。 -- 20、Log组件异常栈打印支持; + ## 七、其他 diff --git a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java index f9b970ca..b5dabdfc 100644 --- a/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java +++ b/xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java @@ -3,6 +3,8 @@ package com.xxl.job.core.log; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.PrintWriter; +import java.io.StringWriter; import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -49,8 +51,6 @@ public class XxlJobLogger { /** * append log with pattern * - * @ - * * @param appendLogPattern like "aaa {0} bbb {1} ccc" * @param appendLogArguments like "111, true" */ @@ -59,4 +59,16 @@ public class XxlJobLogger { log(appendLog); } + /** + * append exception stack + * + * @param e + */ + public static void log(Throwable e) { + StringWriter stringWriter = new StringWriter(); + e.printStackTrace(new PrintWriter(stringWriter)); + String appendLog = stringWriter.toString(); + log(appendLog); + } + }