Tailing a file in Clojure? -


what best method tail file in clojure? haven't come across utilities so, ideas on how build 1 appreciated!

thanks.

as kotarak stated, use randomaccessfile seek end of file. unfortunately have busy-wait/sleep changes.

using lazy sequence can process lines "on-the-fly":

(import java.io.randomaccessfile)  (defn raf-seq   [#^randomaccessfile raf]   (if-let [line (.readline raf)]     (lazy-seq (cons line (raf-seq raf)))     (do (thread/sleep 1000)         (recur raf))))  (defn tail-seq [input]   (let [raf (randomaccessfile. input "r")]     (.seek raf (.length raf))     (raf-seq raf)))  ; read next 10 lines (take 10 (tail-seq "/var/log/mail.log")) 

update:

something tail -f /var/log/mail.log -n 0, using doseq, changes consumed.

(doseq [line (tail-seq "/var/log/mail.log")] (println line)) 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -