I'd like to observe a log file which is continuously updated by the system. I thought about using a Comet actor to do that but I need advice for the right direction. I want to achieve similar functionality to tail -F for the WebApp. If something new is written to the log file the Comet actor should pick it up continually. I want to show this information on a webpage. How can I achieve this with the Lift framework and Scala?
1 Answers
You need to solve 2 problems separately: log tailing, and comet page updates and then put everything together:
The way I would do it is by creating an Akka/Scala/Lift actor that tails the log. Look at this question for example on how to tail a log file in Java. Then whenever this actor detects some changes in the log it should send a message to the comet actor which in turn will update the web page. You can easily find general examples on how to use Comet, for example here.
If you don't want to use an actor then just schedule a thread that runs and tails the log.
Note that if your log rotates and/or archives you'll have to deal with it too.
A completely alternative solution would be to hook up custom log appender or custom logger, for example this and make it send you log events. I think if you use Akka Logger you can simply subscribe to the event which your actor will receive on each log event, which you just forward to the Comet actor in a similar manner to the solution above.