我的代码如下.
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);
 }
}
Run Code Online (Sandbox Code Playgroud)
.ie,我正在监视日志文件.每当在日志文件(c:\ development\temp\test.log)中更新日志消息时,它将打印日志消息.
问题是,每当日志文件中的日志消息更新时,它会显示相同的日志消息两次,有时也会显示三到四次.以避免这些重复的日志消息.