in java TailListener,how to avoid duplicate log messages

前端 未结 3 401
伪装坚强ぢ
伪装坚强ぢ 2021-01-19 19:37

my code is given below .

public static void main(String[] args) {
        // TODO code application logic here
        File pcounter_log = new File(\"c:\\deve         


        
相关标签:
3条回答
  • 2021-01-19 20:09

    Following code removed the issue with two invocations of the TailerListenerAdapter:handle function.

    TailerListener listener = new TailerListener(topic);
    Tailer tailer = new Tailer(new File(path), listener, sleep, true);
    Thread thread = new Thread(tailer);
    thread.setDaemon(true);
    thread.start(); 
    
    0 讨论(0)
  • 2021-01-19 20:16

    Looking at the code of Tailer, I can't see how that can happen. Are you sure that you aren't running multiple copies of the tailer, and that the messages aren't actually duplicated in the log file.

    0 讨论(0)
  • 2021-01-19 20:21

    One of the reasons for the duplicate messages is that if you are using the Tailer.create static method to create the Tailer, it automatically starts the process of monitoring the log.

    We make the mistake of doing a tailer.run which starts another monitoring instance and prints the same entries twice.

    0 讨论(0)
提交回复
热议问题