我的代码如下。在java中TailListener,如何避免重复的日志消息
public static void main(String[] args) {
// TODO code application logic here
File pcounter_log = new File("c:\development\temp\test.log");
try {
TailerListener listener = new PCTailListener();
Tailer tailer = new Tailer(pcounter_log, listener, 5000,true);
Thread thread = new Thread(tailer);
thread.start();
} catch (Exception e) {
System.out.println(e);
}
}
public class PCTailListener extends TailerListenerAdapter {
public void handle(String line) {
System.out.println(line);
}
}
.IE,我监测file.whenever登录日志文件更新消息的日志(C:\研发\ TEMP \ test.log中),将打印日志消息。
问题是,无论何时在日志文件中更新日志消息,它都会显示相同的日志消息两次,有时候会显示三次或四次,以避免重复的日志消息。