This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
Capturing the changes made to file(s) in a directory
Mohammad Akon
Greenhorn
Joined: Jul 17, 2007
Posts: 19
posted
0
Hello all,
I am developing an application that is monitoring the files (text files only) within a directory. The monitoring part is fine (thanks to threads on file watch). But is there an "efficient" way to capture the modifications made to those files (I need those changes to for reporting)? By efficiency I tried to mean....not going through the whole file again an again and looking for changes....may be using some sort of time-stamps/tag to identify last read line from the files and then read to the EOF?
May be there are other posts on the same topic but unfortunately I could not find them. Would appreciate if anyone can shed some light.
If you are only looking for data appended to the file, then you could keep track of the previous length of the file and, after data is appended, start reading the file after the previous length. (Hint: RandomAccessFile)
However if you're trying to extract data from a log file on a timely basis, it would be more practical to modify the logging so that you didn't have to hack the log files. For example if you were using log4j you could use its appender which sends data to a socket, and write a socket listener which would then receive the logs directly.
However if you're trying to extract data from a log file on a timely basis, it would be more practical to modify the logging so that you didn't have to hack the log files. For example if you were using log4j you could use its appender which sends data to a socket, and write a socket listener which would then receive the logs directly.
The Log4j site has appenders for publishing to Multicast (unreliable but pretty fast) and for JMS (reliable). Of course one would need a JMS server to use JMS but there are several free ones out there.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Mohammad Akon
Greenhorn
Joined: Jul 17, 2007
Posts: 19
posted
0
James Sabre wrote:
Paul Clapham wrote:
However if you're trying to extract data from a log file on a timely basis, it would be more practical to modify the logging so that you didn't have to hack the log files. For example if you were using log4j you could use its appender which sends data to a socket, and write a socket listener which would then receive the logs directly.
The Log4j site has appenders for publishing to Multicast (unreliable but pretty fast) and for JMS (reliable). Of course one would need a JMS server to use JMS but there are several free ones out there.
But the problem is I do not have access to the available logger(s). Some the third party applications are generating the log files and I do not know what kind of logger they are using and cannot do any computation with them. All I have are the few log files. And yes, I'll be populating msgs to a remote JMS Queue for further msg consumption.
Mohammad Akon wrote:But the problem is I do not have access to the available logger(s). Some the third party applications are generating the log files and I do not know what kind of logger they are using and cannot do any computation with them. All I have are the few log files. And yes, I'll be populating msgs to a remote JMS Queue for further msg consumption.
Yeah, I kind of expected this sort of answer. However you might consider inquiring a little more closely; if they are using log4j then you might be able to find the log4j configuration file and add in your own appenders. Provided of course there weren't management or legal issues involved in doing that.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Capturing the changes made to file(s) in a directory