Log组件支持输出异常栈信息,底层实现优化

master
xuxueli 7 years ago
parent 5e39a95478
commit 451eb2b7b3
  1. 2
      doc/XXL-JOB官方文档.md
  2. 22
      xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java

@ -1064,7 +1064,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 10、执行器端口支持随机生成(小于等于0时),避免端口定义冲突;
- 11、任务Cron长度扩展支持至128位;
- 12、调度报表优化,支持时间区间筛选;
- 13、Log组件支持输出异常栈信息;
- 13、Log组件支持输出异常栈信息,底层实现优化
### TODO LIST
- 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;

@ -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);
}
}

Loading…
Cancel
Save