Simple Logging System
Closed this issue · 2 comments
pwhittin commented
I'm trying to implement a simple logging system. The following is the code for the system.
When (-main) is executed only the first log string "one" is logged.
Any suggestions?
(ns otplike-log.core
(:require [otplike.process :as process :refer [!]])
(:gen-class))
(defn log-string-to-file
[log-file-spec]
(fn
[log-message]
(spit log-file-spec (str log-message "\n") :append true)))
(process/proc-defn
log-proc
[log-string-fn]
(process/receive!
msg (log-string-fn msg)))
(defn create-log
[log-string-fn]
(let [log (process/spawn log-proc [log-string-fn])]
(fn
[log-string]
(! log log-string))))
(defn -main
[& args]
(let [log (create-log (log-string-to-file "log.txt"))]
(log "one")
(log "two")
(log "three")))
pwhittin commented
After some trial and error I discovered that the following implementation of "log-proc" works. Does this look correct?
(process/proc-defn
log-proc
[log-string-fn]
(process/receive!
msg (do (log-string-fn msg)
(recur log-string-fn))))
sskorokhodov commented
Looks good!