|
|
@@ -1,12 +1,15 @@
|
|
|
package cn.reghao.bnt.logstash.service;
|
|
|
|
|
|
import cn.reghao.bnt.logstash.ws.WsClient;
|
|
|
+import cn.reghao.jutil.jdk.io.TextFile;
|
|
|
import cn.reghao.jutil.jdk.serializer.JsonConverter;
|
|
|
import cn.reghao.jutil.jdk.web.log.NginxLog;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
+import java.io.IOException;
|
|
|
import java.io.RandomAccessFile;
|
|
|
+import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
@@ -18,12 +21,16 @@ public class TailReader implements Runnable {
|
|
|
private final RandomAccessFile raf;
|
|
|
private long pointer;
|
|
|
private final WsClient wsClient;
|
|
|
+ private TextFile textFile;
|
|
|
+ private String errorLogPath;
|
|
|
|
|
|
public TailReader(String filePath, WsClient wsClient) throws FileNotFoundException {
|
|
|
this.filePath = filePath;
|
|
|
this.raf = new RandomAccessFile(filePath, "r");
|
|
|
this.pointer = 0;
|
|
|
this.wsClient = wsClient;
|
|
|
+ this.textFile = new TextFile();
|
|
|
+ this.errorLogPath = System.getProperty("user.dir") + "/logs/error.log";
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -71,6 +78,11 @@ public class TailReader implements Runnable {
|
|
|
wsClient.send("", nginxLog);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ try {
|
|
|
+ textFile.append(errorLogPath, List.of(line));
|
|
|
+ } catch (IOException ex) {
|
|
|
+ ex.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|