From 451eb2b7b32bc309dd46408f9af4c35e79e2fc48 Mon Sep 17 00:00:00 2001 From: xuxueli <931591021@qq.com> Date: Tue, 19 Dec 2017 21:43:48 +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?= =?UTF-8?q?=EF=BC=8C=E5=BA=95=E5=B1=82=E5=AE=9E=E7=8E=B0=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 | 2 +- .../com/xxl/job/core/log/XxlJobLogger.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md index 717e2991..dd9ee7f4 100644 --- a/doc/XXL-JOB官方文档.md +++ b/doc/XXL-JOB官方文档.md @@ -1064,7 +1064,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段 - 10、执行器端口支持随机生成(小于等于0时),避免端口定义冲突; - 11、任务Cron长度扩展支持至128位; - 12、调度报表优化,支持时间区间筛选; -- 13、Log组件支持输出异常栈信息; +- 13、Log组件支持输出异常栈信息,底层实现优化; ### TODO LIST - 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限; 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 b5dabdfc..32043ef2 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 @@ -19,9 +19,10 @@ public class XxlJobLogger { /** * append log * + * @param callInfo * @param appendLog */ - public static void log(String appendLog) { + private static void logDetail(StackTraceElement callInfo, String appendLog) { // logFileName String logFileName = XxlJobFileAppender.contextHolder.get(); @@ -29,9 +30,9 @@ public class XxlJobLogger { return; } - // "yyyy-MM-dd HH:mm:ss [ClassName]-[MethodName]-[LineNumber]-[ThreadName] log"; + /*// "yyyy-MM-dd HH:mm:ss [ClassName]-[MethodName]-[LineNumber]-[ThreadName] log"; StackTraceElement[] stackTraceElements = new Throwable().getStackTrace(); - StackTraceElement callInfo = stackTraceElements[1]; + StackTraceElement callInfo = stackTraceElements[1];*/ StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(xxlJobLoggerFormat.format(new Date())).append(" ") @@ -55,8 +56,14 @@ public class XxlJobLogger { * @param appendLogArguments like "111, true" */ public static void log(String appendLogPattern, Object ... appendLogArguments) { - String appendLog = MessageFormat.format(appendLogPattern, appendLogArguments); - log(appendLog); + + String appendLog = appendLogPattern; + if (appendLogArguments!=null && appendLogArguments.length>0) { + appendLog = MessageFormat.format(appendLogPattern, appendLogArguments); + } + + StackTraceElement callInfo = new Throwable().getStackTrace()[1]; + logDetail(callInfo, appendLog); } /** @@ -65,10 +72,13 @@ public class XxlJobLogger { * @param e */ public static void log(Throwable e) { + StringWriter stringWriter = new StringWriter(); e.printStackTrace(new PrintWriter(stringWriter)); String appendLog = stringWriter.toString(); - log(appendLog); + + StackTraceElement callInfo = new Throwable().getStackTrace()[1]; + logDetail(callInfo, appendLog); } }