|
@@ -23,30 +23,43 @@ public class XxlJobFileAppender extends AppenderSkeleton {
|
23
|
23
|
public void setFilePath(String filePath) {
|
24
|
24
|
XxlJobFileAppender.filePath = filePath;
|
25
|
25
|
}
|
26
|
|
-
|
|
26
|
+
|
|
27
|
+ /**
|
|
28
|
+ * log filename: yyyy-MM-dd/9999.log
|
|
29
|
+ *
|
|
30
|
+ * @param triggerDate
|
|
31
|
+ * @param logId
|
|
32
|
+ * @return
|
|
33
|
+ */
|
|
34
|
+ public static String makeLogFileName(Date triggerDate, int logId) {
|
|
35
|
+
|
|
36
|
+ // filePath/
|
|
37
|
+ File filePathDir = new File(filePath);
|
|
38
|
+ if (!filePathDir.exists()) {
|
|
39
|
+ filePathDir.mkdirs();
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ // filePath/yyyy-MM-dd/
|
|
43
|
+ String nowFormat = sdf.format(new Date());
|
|
44
|
+ File filePathDateDir = new File(filePathDir, nowFormat);
|
|
45
|
+ if (!filePathDateDir.exists()) {
|
|
46
|
+ filePathDateDir.mkdirs();
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ // filePath/yyyy-MM-dd/9999.log
|
|
50
|
+ String logFileName = XxlJobFileAppender.sdf.format(triggerDate).concat("/").concat(String.valueOf(logId)).concat(".log");
|
|
51
|
+ return logFileName;
|
|
52
|
+ }
|
|
53
|
+
|
27
|
54
|
@Override
|
28
|
55
|
protected void append(LoggingEvent event) {
|
29
|
|
- String trigger_log_id = contextHolder.get();
|
30
|
|
- if (trigger_log_id==null || trigger_log_id.trim().length()==0) {
|
|
56
|
+
|
|
57
|
+ String logFileName = contextHolder.get();
|
|
58
|
+ if (logFileName==null || logFileName.trim().length()==0) {
|
31
|
59
|
return;
|
32
|
60
|
}
|
33
|
|
-
|
34
|
|
- // filePath/
|
35
|
|
- File filePathDir = new File(filePath);
|
36
|
|
- if (!filePathDir.exists()) {
|
37
|
|
- filePathDir.mkdirs();
|
38
|
|
- }
|
39
|
|
-
|
40
|
|
- // filePath/yyyy-MM-dd/
|
41
|
|
- String nowFormat = sdf.format(new Date());
|
42
|
|
- File filePathDateDir = new File(filePathDir, nowFormat);
|
43
|
|
- if (!filePathDateDir.exists()) {
|
44
|
|
- filePathDateDir.mkdirs();
|
45
|
|
- }
|
46
|
|
-
|
47
|
|
- // filePath/yyyy-MM-dd/9999.log
|
48
|
|
- String logFileName = trigger_log_id.concat(".log");
|
49
|
|
- File logFile = new File(filePathDateDir, logFileName);
|
|
61
|
+ File logFile = new File(filePath, logFileName);
|
|
62
|
+
|
50
|
63
|
if (!logFile.exists()) {
|
51
|
64
|
try {
|
52
|
65
|
logFile.createNewFile();
|
|
@@ -101,31 +114,16 @@ public class XxlJobFileAppender extends AppenderSkeleton {
|
101
|
114
|
|
102
|
115
|
/**
|
103
|
116
|
* support read log-file
|
104
|
|
- * @param triggerDate
|
105
|
|
- * @param trigger_log_id
|
|
117
|
+ * @param logFileName
|
106
|
118
|
* @return log content
|
107
|
119
|
*/
|
108
|
|
- public static String readLog(Date triggerDate, int trigger_log_id ){
|
109
|
|
- if (triggerDate==null || trigger_log_id<=0) {
|
|
120
|
+ public static String readLog(String logFileName ){
|
|
121
|
+
|
|
122
|
+ if (logFileName==null || logFileName.trim().length()==0) {
|
110
|
123
|
return null;
|
111
|
124
|
}
|
112
|
|
-
|
113
|
|
- // filePath/
|
114
|
|
- File filePathDir = new File(filePath);
|
115
|
|
- if (!filePathDir.exists()) {
|
116
|
|
- filePathDir.mkdirs();
|
117
|
|
- }
|
118
|
|
-
|
119
|
|
- // filePath/yyyy-MM-dd/
|
120
|
|
- String nowFormat = sdf.format(triggerDate);
|
121
|
|
- File filePathDateDir = new File(filePathDir, nowFormat);
|
122
|
|
- if (!filePathDateDir.exists()) {
|
123
|
|
- filePathDateDir.mkdirs();
|
124
|
|
- }
|
125
|
|
-
|
126
|
|
- // filePath/yyyy-MM-dd/9999.log
|
127
|
|
- String logFileName = String.valueOf(trigger_log_id).concat(".log");
|
128
|
|
- File logFile = new File(filePathDateDir, logFileName);
|
|
125
|
+ File logFile = new File(filePath, logFileName);
|
|
126
|
+
|
129
|
127
|
if (!logFile.exists()) {
|
130
|
128
|
return null;
|
131
|
129
|
}
|