sandbox-java/tailer/src/main/java/de/swingbe/tailer/Main.java

41 lines
1.1 KiB
Java
Raw Normal View History

2021-11-30 15:19:00 +01:00
package de.swingbe.tailer;
import org.apache.commons.io.input.Tailer;
import org.apache.commons.io.input.TailerListener;
2021-11-30 17:13:15 +01:00
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
2021-11-30 15:19:00 +01:00
import java.io.File;
public class Main {
2021-11-30 17:13:15 +01:00
public final static Logger LOG = LoggerFactory.getLogger(Main.class);
2021-11-30 15:19:00 +01:00
//delay between checks of the file for new content in milliseconds
public static final int DELAY_MILLIS = 500;
//set to true to tail from the end of the file, false to tail from the beginning of the file
public static final boolean END = true;
2021-11-30 15:19:00 +01:00
public static void main(String[] args) {
2021-11-30 17:13:15 +01:00
LOG.trace("Entering application.");
2021-11-30 15:19:00 +01:00
2021-11-30 15:19:53 +01:00
TailerListener listener = new MyListener();
//create and use a Tailer with a Thread
2021-11-30 17:13:15 +01:00
String fileName = "/opt/npm/NetPeerManager.log";
//TODO What is the behaviour of the reOpen parameter?
Tailer tailer = new Tailer(new File(fileName), listener, DELAY_MILLIS, END);
2021-11-30 15:19:53 +01:00
tailer.run();
Thread thread = new Thread(tailer);
//optional
thread.setDaemon(true);
thread.start();
2021-11-30 17:13:15 +01:00
LOG.trace("Exiting application.");
2021-11-30 15:19:00 +01:00
return;
}
}