views:

190

answers:

5

What is the most efficient(fast and safe) way of reading a log file in java? The log file continuously(almost every second) gets updated.

+1  A: 

Tricky, and depends on many variables, but you might want to take a look at BufferedReader and see if does what you need.

http://java.sun.com/j2se/1.4.2/docs/api/java/io/BufferedReader.html

Lance Rushing
+1  A: 

Assuming you are talking about server logs then you might want to look at an existing tool like Splunk.

Taylor Leese
+2  A: 

Looks like Apache JMeter (open source, friendly licensing) has some classes that you may be able to reuse which parse Tomcat access logs. Internally, these classes are used in JMeter for the Access Log Sampler which is a tool that simulates production traffic in development environments by parsing access logs and generating HTTP requests to a development web server based on the logs. You can probably reuse just the log parsing functionality for your own purposes.

Asaph
+1  A: 

I've had really good luck with Chainsaw.

Dean J
A: 

If you just want to follow the output the "tail -f foobar.log" works well. If you are on a Windows machine, it is available with Cygwin. http://www.cygwin.com/.

Thorbjørn Ravn Andersen
Thanks, But i am looking for a solution which specifically uses java
Sudheer
In that case please elaborate on precisely what functionality you expect. Watching a log file scroll by?
Thorbjørn Ravn Andersen