使用Ajax的流日志文件

I have the need to stream a log file that is located on FTP, its from a remote server.

I am not sure how to stream this, possibly with Ajax.

There are a few things on google, but i cannot seem to find something that can access remote FTP and stream the file.

Maybe with Ajax and using intervals, then scrolling down to the bottom of the page.

Note that the log file is being updated constantly and people will also be sending commands to the server, thus updating the log file. Will refreshing the log and downloading the log each time be slow? Some log files can be very large.

I would think you would need some sort of intermediate script to keep track of the last read lines of the logfile and the respond to the AJAX call with any updates to the file since that point.

My psuedo-code solution would look like this

  • Read local cache file for last line number that was processed
  • Count number of lines in the file (using linux wc -l or similar)
  • Get the last X number of lines from the files as calculated from the difference (linux tail -n X or similar)
  • Update local cache file with last line number read.
  • Return the content to the caller.

Stop using the filesystem and implement publish-subscriber pattern. For a reference implementation see loggly or papertrail.