Using Ruby and jQuery to tail log files
I need to hack up a quick webpage that displays a log file in real time as contents get added to that file.
For example, it would be like a real-time tail -f开发者_如何转开发 error_log
type of command but would be constantly updated on the webpage.
Has anyone seen/heard/dreamt of a Ruby/jQuery solution already out there? (Plugin, gem, etc.)?
Well, it is impossible to show things exactly live, unless you have complete control over the thing writing to the log.
Something could automatically refresh the contents every 10-20 seconds.
On the first request, everything would be show. Then the AJAX requests would send the last line the client has then Ruby would have to open the file, find that line and send everything after that back.
This would be hard on the server with anything more than 1 or 2 clients. The real difficulty is that the server cannot 'push' changes to the client, the client can only check in and see if their are changes.
I know 0 Ruby, so I can't write anything for you, but that is how it would go.
You're not going to do it with standard design approaches, but using a pubsub approach would work. You might check out node.js for one approach. Another would be to use a recursive ajax query that queries for changes in the log file.
精彩评论