I want to use core.async as a logger that writes out to a file, so I created a test.txt file, stuck it in my resources folder and wrote this code:
(use 'clojure.java.io)
(use 'clojure.core.async)
(def print-chan (chan))
(go (loop []
(when-let [v (<! print-chan)]
(with-open [wrtr (writer "resources/test.txt" :append true)]
(.write wrtr v))
(recur))))
(>!! print-chan 42)
When I run this, however, I find that it will only replace what is in the file, and not append to it. Also, sometimes the output that is written to the file is odd. Once, I tried to put 42 and I got * instead. When I use the writer without the core.async functions, it works as expected. What is the idiomatic way to write to a log file in Clojure using core.async? Thanks in advance!
*I am using light table.