Hi Scott and Paul,

I have been working on my first task to fix the tailing capability of VFS
log receiver, for last few days. First of all I would like to describe why
tailing is not working in the current implementation as I understand and
then I will suggest my solution.

Current Implementation
In the current implementation, in VFSLogFilePatternReceiver, VFSReader
creates a FileSystemManager and makes a FileObject by giving the file URL
using the created FileSysemManager. After that it creates an
InputStreamReader to read the log file and passes it to the process(reader)
method in the LogFilePatternReceiver in log4j. In this process() method, a
BufferedReader is created using the reader passed and this BufferedReader is
checked for new lines (new logs in the log file), until 'tailing' is kept
true.
This works for URLs in the local file system (Eg: file:///foo/bar.log ) as
the BufferedReader is updated whenever a new line is written to the file.
But when the log file is accessed through some other protocol, say http,
this Buffered reader is not updated through the protocol when new lines are
added to the log file. That's why tailing is not working with such a
protocol.

My Solution
As I can see, keeping only the InputStreamReader of the file in the method
we run the while loop (the loop which runs until 'tailiing' is kept true) is
not going to work. And also we can't pass a FileObject to the process()
method as it is a method in a standardized interface. So I think the above
while loop should run inside VFSReader (in VFSLogFilePatternReceiver) in
which we have the access to the FileObject of the log file. Then we can get
this working by getting the randomAccessContent of the log file, inside the
while loop and seeking for the line pointed by the file pointer.

According to the method proposed by Mario on the VFS team, this can be done
in the following manner.

//This part comes inside the VFSReader class...
long lastFilePointer = 0;
do
{
  RadomAccessContent rac = FileObject.getRandomAccessContent()
  rac.seek(lastFilePointer)
  reader = new InputStreamReader(rac.getInputStream());
  process(reader);
  lastFilePointer = rac.getFilePointer();
  rac.close();
}while (isTailing());

Here, as the while loop is taken out of the process() method,
activateOptions() method in the LogFilePatternReceiver should also be
changed as it calls the process() method.

If this method is okay, I can send the patch with the modifications
mentioned above. Your comments are welcome..

Thanks,
~Isuru

Reply via email to