|
|
@@ -20,53 +20,47 @@ public class XxlJobFileAppender {
|
|
20
|
20
|
public static final InheritableThreadLocal<String> contextHolder = new InheritableThreadLocal<String>();
|
|
21
|
21
|
|
|
22
|
22
|
|
|
23
|
|
- private static String logPath = "/data/applogs/xxl-job/jobhandler/";
|
|
|
23
|
+ // log base path
|
|
|
24
|
+ private static String logBasePath = "/data/applogs/xxl-job/jobhandler";
|
|
24
|
25
|
public static void initLogPath(String logPath){
|
|
25
|
26
|
// init
|
|
26
|
27
|
if (logPath!=null && logPath.trim().length()>0) {
|
|
27
|
|
- /*if (!logPath.endsWith("/")) {
|
|
28
|
|
- logPath = logPath.concat("/");
|
|
29
|
|
- }*/
|
|
30
|
|
- XxlJobFileAppender.logPath = logPath;
|
|
|
28
|
+ logBasePath = logPath;
|
|
31
|
29
|
}
|
|
32
|
|
- // mk dir
|
|
33
|
|
- File logPathDir = new File(XxlJobFileAppender.logPath);
|
|
|
30
|
+ // mk base dir
|
|
|
31
|
+ File logPathDir = new File(logBasePath);
|
|
34
|
32
|
if (!logPathDir.exists()) {
|
|
35
|
33
|
logPathDir.mkdirs();
|
|
36
|
34
|
}
|
|
37
|
|
- XxlJobFileAppender.logPath = logPathDir.getPath();
|
|
|
35
|
+ logBasePath = logPathDir.getPath();
|
|
|
36
|
+
|
|
|
37
|
+ // mk glue dir
|
|
|
38
|
+ File glueBaseDir = new File(logPathDir, "gluesource");
|
|
|
39
|
+ if (!glueBaseDir.exists()) {
|
|
|
40
|
+ glueBaseDir.mkdirs();
|
|
|
41
|
+ }
|
|
38
|
42
|
}
|
|
39
|
43
|
public static String getLogPath() {
|
|
40
|
|
- return logPath;
|
|
|
44
|
+ return logBasePath;
|
|
41
|
45
|
}
|
|
42
|
46
|
|
|
43
|
47
|
|
|
44
|
48
|
/**
|
|
45
|
|
- * log filename: yyyy-MM-dd/9999.log
|
|
|
49
|
+ * log filename, like "logPath/yyyy-MM-dd/9999.log"
|
|
46
|
50
|
*
|
|
47
|
51
|
* @param triggerDate
|
|
48
|
52
|
* @param logId
|
|
49
|
53
|
* @return
|
|
50
|
54
|
*/
|
|
51
|
55
|
public static String makeLogFileName(Date triggerDate, int logId) {
|
|
52
|
|
-
|
|
53
|
|
- // filePath/
|
|
54
|
|
- File filePathDir = new File(logPath);
|
|
55
|
|
- if (!filePathDir.exists()) {
|
|
56
|
|
- filePathDir.mkdirs();
|
|
57
|
|
- }
|
|
58
|
|
-
|
|
59
|
|
- // filePath/yyyy-MM-dd/
|
|
|
56
|
+ // filePath/yyyy-MM-dd/9999.log
|
|
60
|
57
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); // avoid concurrent problem, can not be static
|
|
61
|
|
-
|
|
62
|
|
- String nowFormat = sdf.format(new Date());
|
|
63
|
|
- File filePathDateDir = new File(filePathDir, nowFormat);
|
|
64
|
|
- if (!filePathDateDir.exists()) {
|
|
65
|
|
- filePathDateDir.mkdirs();
|
|
66
|
|
- }
|
|
67
|
|
-
|
|
68
|
|
- // filePath/yyyy-MM-dd/9999.log
|
|
69
|
|
- String logFileName = sdf.format(triggerDate).concat("/").concat(String.valueOf(logId)).concat(".log");
|
|
|
58
|
+ String logFileName = getLogPath()
|
|
|
59
|
+ .concat("/")
|
|
|
60
|
+ .concat(sdf.format(triggerDate))
|
|
|
61
|
+ .concat("/")
|
|
|
62
|
+ .concat(String.valueOf(logId))
|
|
|
63
|
+ .concat(".log");
|
|
70
|
64
|
return logFileName;
|
|
71
|
65
|
}
|
|
72
|
66
|
|
|
|
@@ -78,17 +72,11 @@ public class XxlJobFileAppender {
|
|
78
|
72
|
*/
|
|
79
|
73
|
public static void appendLog(String logFileName, String appendLog) {
|
|
80
|
74
|
|
|
81
|
|
- // log
|
|
82
|
|
- if (appendLog == null) {
|
|
83
|
|
- appendLog = "";
|
|
84
|
|
- }
|
|
85
|
|
- appendLog += "\r\n";
|
|
86
|
|
-
|
|
87
|
75
|
// log file
|
|
88
|
76
|
if (logFileName==null || logFileName.trim().length()==0) {
|
|
89
|
77
|
return;
|
|
90
|
78
|
}
|
|
91
|
|
- File logFile = new File(logPath, logFileName);
|
|
|
79
|
+ File logFile = new File(logFileName);
|
|
92
|
80
|
|
|
93
|
81
|
if (!logFile.exists()) {
|
|
94
|
82
|
try {
|
|
|
@@ -98,6 +86,12 @@ public class XxlJobFileAppender {
|
|
98
|
86
|
return;
|
|
99
|
87
|
}
|
|
100
|
88
|
}
|
|
|
89
|
+
|
|
|
90
|
+ // log
|
|
|
91
|
+ if (appendLog == null) {
|
|
|
92
|
+ appendLog = "";
|
|
|
93
|
+ }
|
|
|
94
|
+ appendLog += "\r\n";
|
|
101
|
95
|
|
|
102
|
96
|
// append file content
|
|
103
|
97
|
try {
|
|
|
@@ -133,7 +127,7 @@ public class XxlJobFileAppender {
|
|
133
|
127
|
if (logFileName==null || logFileName.trim().length()==0) {
|
|
134
|
128
|
return new LogResult(fromLineNum, 0, "readLog fail, logFile not found", true);
|
|
135
|
129
|
}
|
|
136
|
|
- File logFile = new File(logPath, logFileName);
|
|
|
130
|
+ File logFile = new File(logFileName);
|
|
137
|
131
|
|
|
138
|
132
|
if (!logFile.exists()) {
|
|
139
|
133
|
return new LogResult(fromLineNum, 0, "readLog fail, logFile not exists", true);
|