You don’t want to tail a file from a controller, it keeps trying to get new content from the end of the file. If you want to show the last 10 lines, just use the rewind(10) and read until EOF. If you want to simulate the dynamic following of the contents of a file, you need to have a detached, long-running process to do the “tail” and have a periodically_call_remote() in your view to get the new contents.
BackgrounDRb can be a good option for this kind of thing.
You don't want to tail a file from a controller, it keeps trying to get new
content from the end of the file. If you want to show the last 10 lines,
just use the rewind(10) and read until EOF. If you want to simulate the
dynamic following of the contents of a file, you need to have a detached,
long-running process to do the "tail" and have a periodically_call_remote()
in your view to get the new contents.
BackgrounDRb can be a good option for this kind of thing.
Google for my street name, "how to chat", and Rails. I show how to use
periodically_call_remote with some (dated) <script> tricks to send a
"high water mark" back to the server. It only sends chat lines created
since the last high water mark.
and watch the log scroll by with the same effect as "tail -f production.log"
is there a more straight forward way just using logger?
Asked and answered. A web page, by design, is always stateless,
event-driven, and intermittently connected. To scroll a log, you need
a periodical Ajax call, a scrolling div of output, and a high-water
mark. Chat.
Did you ever come up with a solution? I am working on the very same
thing. I have a working (mostly) tail to a div container, but it is
slow and I am not getting all the output from the tail. Wondered how
you have made out. Any feedback would be great. Thanks!