|
|
@@ -6,6 +6,7 @@ import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.web.log.NginxLog;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import java.io.File;
|
|
|
import java.io.FileNotFoundException;
|
|
|
import java.io.IOException;
|
|
|
import java.io.RandomAccessFile;
|
|
|
@@ -30,12 +31,17 @@ public class TailReader implements Runnable {
|
|
|
this.pointer = 0;
|
|
|
this.wsClient = wsClient;
|
|
|
this.textFile = new TextFile();
|
|
|
- this.errorLogPath = System.getProperty("user.dir") + "/logs/error.log";
|
|
|
+ this.errorLogPath = System.getProperty("user.dir") + "/error.log";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void run() {
|
|
|
try {
|
|
|
+ File errLogFile = new File(errorLogPath);
|
|
|
+ if (!errLogFile.exists()) {
|
|
|
+ errLogFile.createNewFile();
|
|
|
+ }
|
|
|
+
|
|
|
//raf.seek(length);
|
|
|
while (!Thread.interrupted()) {
|
|
|
try {
|
|
|
@@ -55,7 +61,7 @@ public class TailReader implements Runnable {
|
|
|
raf.seek(pointer);
|
|
|
String line = raf.readLine();
|
|
|
while (line != null) {
|
|
|
- parseAndPersist(line);
|
|
|
+ parseAndPersist(line, errLogFile);
|
|
|
line = raf.readLine();
|
|
|
}
|
|
|
pointer = length;
|
|
|
@@ -72,14 +78,14 @@ public class TailReader implements Runnable {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void parseAndPersist(String line) {
|
|
|
+ private void parseAndPersist(String line, File errLogFile) {
|
|
|
try {
|
|
|
NginxLog nginxLog = JsonConverter.jsonToObject(line, NginxLog.class);
|
|
|
wsClient.send("", nginxLog);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
try {
|
|
|
- textFile.append(errorLogPath, List.of(line));
|
|
|
+ textFile.append(errLogFile.getAbsolutePath(), List.of(line));
|
|
|
} catch (IOException ex) {
|
|
|
ex.printStackTrace();
|
|
|
}
|