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

pull/6/head
xuxueli 7 years ago
parent 5e39a95478
commit 451eb2b7b3

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

@ -19,9 +19,10 @@ public class XxlJobLogger {
/** /**
* append log * append log
* *
* @param callInfo
* @param appendLog * @param appendLog
*/ */
public static void log(String appendLog) { private static void logDetail(StackTraceElement callInfo, String appendLog) {
// logFileName // logFileName
String logFileName = XxlJobFileAppender.contextHolder.get(); String logFileName = XxlJobFileAppender.contextHolder.get();
@ -29,9 +30,9 @@ public class XxlJobLogger {
return; 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[] stackTraceElements = new Throwable().getStackTrace();
StackTraceElement callInfo = stackTraceElements[1]; StackTraceElement callInfo = stackTraceElements[1];*/
StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(xxlJobLoggerFormat.format(new Date())).append(" ") stringBuffer.append(xxlJobLoggerFormat.format(new Date())).append(" ")
@ -55,8 +56,14 @@ public class XxlJobLogger {
* @param appendLogArguments like "111, true" * @param appendLogArguments like "111, true"
*/ */
public static void log(String appendLogPattern, Object ... appendLogArguments) { 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 * @param e
*/ */
public static void log(Throwable e) { public static void log(Throwable e) {
StringWriter stringWriter = new StringWriter(); StringWriter stringWriter = new StringWriter();
e.printStackTrace(new PrintWriter(stringWriter)); e.printStackTrace(new PrintWriter(stringWriter));
String appendLog = stringWriter.toString(); String appendLog = stringWriter.toString();
log(appendLog);
StackTraceElement callInfo = new Throwable().getStackTrace()[1];
logDetail(callInfo, appendLog);
} }
} }

Loading…
Cancel
Save