I need to monitor a log file for a pattern. The log file continually gets written by an application.
- The application can add new log statements while my program is reading it.
- The log gets rolled over when it’s >200 MB or at end of the day, so my program should handle change in filename dynamically.
- If my program crashes for any reason, it has to resume from where it left off.
I do not want to re-invent the wheel. I am looking for a Java API. I wrote a program to read file and put in a loop with 30 seconds sleep, but that does not meet all the criteria.
You might consider looking at apache commons io classes, in particular Tailer/TailerListener classes. See http://www.devdaily.com/java/jwarehouse/commons-io-2.0/src/main/java/org/apache/commons/io/input/Tailer.java.shtml.