2

我正在使用 java Tail-listener API 来执行 tailf 函数(在 Linux 中)。即,每当日志文件中的日志消息更新时,此 API 都会打印消息。

我的代码如下。

    public static void main(String[] args) {
        // TODO code application logic here
        File pcounter_log = new File("\vat\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);
    }
}

最初它工作正常。一段时间后,它会读取旧的日志消息(在此应用程序启动时生成的日志消息)。它也在阅读新的日志消息。如何避免读取已监控的日志消息。如何执行此操作

4

0 回答 0