in java apache.commons.io,how to avoid to read the old log messages

拈花ヽ惹草 提交于 2019-12-11 01:43:40

问题


i am using the java Tail-listener API to do the tailf function(in Linux).ie,whenever log messages are updated in log file, this API will print the messages.

My code is given below.

    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);
    }
}

Initially its working fine.After some time,its reading the old log messages (log messages which are generated at the time of this application gets started). also its reading new log messages too. how to avoid to read the already monitored log messages.How to do this

来源:https://stackoverflow.com/questions/6332909/in-java-apache-commons-io-how-to-avoid-to-read-the-old-log-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!