Log地址格式兼容,支持非"/"结尾路径配置;

master
xuxueli 7 years ago
parent fc7a502608
commit 3c95ba5ae4
  1. 6
      doc/XXL-JOB官方文档.md
  2. 12
      xxl-job-core/src/main/java/com/xxl/job/core/executor/XxlJobExecutor.java
  3. 8
      xxl-job-core/src/main/java/com/xxl/job/core/handler/impl/ScriptJobHandler.java
  4. 23
      xxl-job-core/src/main/java/com/xxl/job/core/log/XxlJobFileAppender.java
  5. 2
      xxl-job-core/src/main/java/com/xxl/job/core/util/ScriptUtil.java

@ -1077,6 +1077,8 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 12、调度报表优化,支持时间区间筛选;
- 13、Log组件支持输出异常栈信息,底层实现优化;
- 14、失败重试:调度中心调度失败且启用"失败重试"策略时,将会自动重试一次;执行器执行失败且回调失败重试状态时,也将会自动重试一次;
- 15、Log地址格式兼容,支持非"/"结尾路径配置;
### TODO LIST
- 1、任务权限管理:执行器为粒度分配权限,核心操作校验权限;
@ -1096,9 +1098,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 15、Bean模式任务,JobHandler自动从执行器中查询展示为下拉框,选择后自动填充任务名称等属性;
- 16、任务告警邮件优化,调整为表格形式;
- 17、JobHandler提供 init/destroy 方法,支持自定义任务线程销毁逻辑;
- 18、执行器回调地址/日志地址格式兼容,是否已"/"结尾均支持;
- 18、执行器回调地址格式兼容,支持非"/"结尾路径配置;
## 七、其他

@ -72,14 +72,10 @@ public class XxlJobExecutor implements ApplicationContextAware {
initAdminBizList(adminAddresses, accessToken);
// init executor-jobHandlerRepository
if (applicationContext != null) {
initJobHandlerRepository(applicationContext);
}
initJobHandlerRepository(applicationContext);
// init logpath
if (logPath!=null && logPath.trim().length()>0) {
XxlJobFileAppender.logPath = logPath;
}
XxlJobFileAppender.initLogPath(logPath);
// init executor-server
initExecutorServer(port, ip, appName, accessToken);
@ -145,6 +141,10 @@ public class XxlJobExecutor implements ApplicationContextAware {
return jobHandlerRepository.get(name);
}
private static void initJobHandlerRepository(ApplicationContext applicationContext){
if (applicationContext == null) {
return;
}
// init job handler action
Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);

@ -36,20 +36,20 @@ public class ScriptJobHandler extends IJobHandler {
String scriptFileName = null;
if (GlueTypeEnum.GLUE_SHELL == glueType) {
cmd = "bash";
scriptFileName = XxlJobFileAppender.logPath.concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".sh");
scriptFileName = XxlJobFileAppender.getLogPath().concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".sh");
} else if (GlueTypeEnum.GLUE_PYTHON == glueType) {
cmd = "python";
scriptFileName = XxlJobFileAppender.logPath.concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".py");
scriptFileName = XxlJobFileAppender.getLogPath().concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".py");
} else if (GlueTypeEnum.GLUE_NODEJS == glueType) {
cmd = "node";
scriptFileName = XxlJobFileAppender.logPath.concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".js");
scriptFileName = XxlJobFileAppender.getLogPath().concat("gluesource/").concat(String.valueOf(jobId)).concat("_").concat(String.valueOf(glueUpdatetime)).concat(".js");
}
// make script file
ScriptUtil.markScriptFile(scriptFileName, gluesource);
// log file
String logFileName = XxlJobFileAppender.logPath.concat(XxlJobFileAppender.contextHolder.get());
String logFileName = XxlJobFileAppender.getLogPath().concat(XxlJobFileAppender.contextHolder.get());
// invoke
XxlJobLogger.log("----------- script file:"+ scriptFileName +" -----------");

@ -18,7 +18,28 @@ public class XxlJobFileAppender {
// 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>();
public static String logPath = "/data/applogs/xxl-job/jobhandler/";
private static String logPath = "/data/applogs/xxl-job/jobhandler/";
public static void initLogPath(String logPath){
// init
if (logPath!=null && logPath.trim().length()>0) {
/*if (!logPath.endsWith("/")) {
logPath = logPath.concat("/");
}*/
XxlJobFileAppender.logPath = logPath;
}
// mk dir
File logPathDir = new File(XxlJobFileAppender.logPath);
if (!logPathDir.exists()) {
logPathDir.mkdirs();
}
XxlJobFileAppender.logPath = logPathDir.getPath();
}
public static String getLogPath() {
return logPath;
}
/**
* log filename: yyyy-MM-dd/9999.log

@ -28,7 +28,7 @@ public class ScriptUtil {
*/
public static void markScriptFile(String scriptFileName, String content) throws IOException {
// filePath/
File filePathDir = new File(XxlJobFileAppender.logPath);
File filePathDir = new File(XxlJobFileAppender.getLogPath());
if (!filePathDir.exists()) {
filePathDir.mkdirs();
}

Loading…
Cancel
Save