Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java read a logfile live

I'm writing a cod4 server controller in Java(I know there are perfectly fine server controllers out there, but I want to learn from it). Now I want to take specific actions according to entries in a logfile, this file is updated by cod very often, and the file can get quite large. Now how do I efficiently read only the part that has changed of the file, every second or so?

Or is there a way to send everything that is changed in the logfile live to Java?(I read something about pipes). The server runs on linux. It's not needed that the logfile is still saved in the same location, since everything should go through Java I can just save it with that.

A delay of about a second or 2 is acceptable, but not any longer.

like image 872
teuneboon Avatar asked Sep 09 '26 23:09

teuneboon


1 Answers

Maybe you could execute a 'tail -f logfile.txt' subprocess and monitor the output stream?

http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Process.html

like image 112
rohannes Avatar answered Sep 11 '26 11:09

rohannes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!