Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic monitoring of log file

Tags:

java

logging

I need to monitor a log file for a pattern. The log file continually gets written by an application.

  1. The application can add new log statements while my program is reading it.
  2. 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.
  3. 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.

like image 996
nuvatech Avatar asked Oct 03 '11 14:10

nuvatech


People also ask

What is logging in monitoring?

Log monitoring is a process by which developers and administrators continuously observe logs as they're recorded. With log monitoring software, teams can collect information and trigger alerts if something affects system performance and health.

What is a log file monitor used to accomplish?

Log files include information about system performance that can be used to determine when additional capacity is needed to optimize the user experience. Log files can help analysts identify slow queries, errors that are causing transactions to take too long or bugs that impact website or application performance.

How do I see log files in Linux?

This is such a crucial folder on your Linux systems. Open up a terminal window and issue the command cd /var/log. Now issue the command ls and you will see the logs housed within this directory (Figure 1).


1 Answers

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.

like image 197
Kevin Avatar answered Sep 29 '22 04:09

Kevin