日志组件逻辑调整:日志组件改为通过 XxlJobContent 获取任务上下文并匹配写入对应日志文件;

master
xuxueli 5 years ago
parent e17797888c
commit 2d153e56e7
  1. 3
      doc/XXL-JOB官方文档.md
  2. 2
      xxl-job-core/src/main/java/com/xxl/job/core/context/XxlJobContext.java
  3. 2
      xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java
  4. 5
      xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
  5. 4
      xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobLogger.java
  6. 2
      xxl-job-core/src/main/java/com/xxl/job/core/thread/JobThread.java
  7. 7
      xxl-job-core/src/main/java/com/xxl/job/core/thread/TriggerCallbackThread.java

@ -1992,7 +1992,8 @@ data: post-data
- 4、多个项目依赖升级至较新稳定版本,如netty、spring、springboot等;
- 5、通用HTTP任务Handler(httpJobHandler)优化:修复 "setDoOutput(true)" 导致任务请求GetMethod失效问题;
- 6、新增任务属性 "XxlJobContent" ,统一维护任务上下文信息,包括任务ID、分片参数等,方便运行时存取任务相关信息;
- 废弃 "ShardingUtil" 组件:改用 "XxlJobContext.getXxlJobContext().getShardIndex()/getShardTotal();" 获取分片参数;
- 6.1、废弃 "ShardingUtil" 组件:改用 "XxlJobContext.getXxlJobContext().getShardIndex()/getShardTotal();" 获取分片参数;
- 6.2、日志组件逻辑调整:日志组件改为通过 XxlJobContent 获取任务上下文并匹配写入对应日志文件;
- 7、[规划中]任务触发参数优化:支持选择 "Cron触发"、"固定间隔时间触发"、"指定时间点触发"、"不选择" 等;
### 7.32 版本 v2.3.0 Release Notes[规划中]

@ -55,7 +55,7 @@ public class XxlJobContext {
// ---------------------- tool ----------------------
private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>();
private static InheritableThreadLocal<XxlJobContext> contextHolder = new InheritableThreadLocal<XxlJobContext>(); // support for child thread of job handler)
public static void setXxlJobContext(XxlJobContext xxlJobContext){
contextHolder.set(xxlJobContext);

@ -68,7 +68,7 @@ public class ScriptJobHandler extends IJobHandler {
}
// log file
String logFileName = XxlJobFileAppender.contextHolder.get();
String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName();
// script params:0=param、1=分片序号、2=分片总数
String[] scriptParams = new String[3];

@ -15,11 +15,6 @@ import java.util.Date;
public class XxlJobFileAppender {
private static Logger logger = LoggerFactory.getLogger(XxlJobFileAppender.class);
// for JobThread (support log for child thread of job handler)
//public static ThreadLocal<String> contextHolder = new ThreadLocal<String>();
public static final InheritableThreadLocal<String> contextHolder = new InheritableThreadLocal<String>();
/**
* log base path
*

@ -1,5 +1,6 @@
package com.xxl.job.core.log;
import com.xxl.job.core.context.XxlJobContext;
import com.xxl.job.core.util.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -38,7 +39,8 @@ public class XxlJobLogger {
String formatAppendLog = stringBuffer.toString();
// appendlog
String logFileName = XxlJobFileAppender.contextHolder.get();
String logFileName = XxlJobContext.getXxlJobContext().getJobLogFileName();
if (logFileName!=null && logFileName.trim().length()>0) {
XxlJobFileAppender.appendLog(logFileName, formatAppendLog);
} else {

@ -123,8 +123,6 @@ public class JobThread extends Thread{
triggerParam.getBroadcastIndex(),
triggerParam.getBroadcastTotal()));
XxlJobFileAppender.contextHolder.set(logFileName);
// execute
XxlJobLogger.log("<br>----------- xxl-job job execute start -----------<br>----------- Param:" + triggerParam.getExecutorParams());

@ -3,6 +3,7 @@ package com.xxl.job.core.thread;
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.context.XxlJobContext;
import com.xxl.job.core.enums.RegistryConfig;
import com.xxl.job.core.executor.XxlJobExecutor;
import com.xxl.job.core.log.XxlJobFileAppender;
@ -187,7 +188,11 @@ public class TriggerCallbackThread {
private void callbackLog(List<HandleCallbackParam> callbackParamList, String logContent){
for (HandleCallbackParam callbackParam: callbackParamList) {
String logFileName = XxlJobFileAppender.makeLogFileName(new Date(callbackParam.getLogDateTim()), callbackParam.getLogId());
XxlJobFileAppender.contextHolder.set(logFileName);
XxlJobContext.setXxlJobContext(new XxlJobContext(
-1,
logFileName,
-1,
-1));
XxlJobLogger.log(logContent);
}
}

Loading…
Cancel
Save