开发者

what is the most efficient way of reading a log file in java?

What is the most efficient(fast and safe) way of reading a log file in java? The log file continuously(almost every second) gets update开发者_StackOverflow社区d.


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.


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


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


I've had really good luck with Chainsaw.


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/.


If you want to tail a particular file, you can look at Tailer. This class will work both for windows and *nix systems. You should be careful while reading a file in windows, because most of the log rotation programs, would try to rename the file. If you hold a lock on that file, the renaming would fail.

If you are looking at managing a directory with log files, this would be a good thing to look for Most efficient way to tail/poll a log file in Java

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜