Fork me on GitHub

is there a nice character literal for the escape key like there is for \newline and \space ?

Alex Miller (Clojure team)17:10:54

the list there is the list


Hey guys, so I decided to go with mulog for a logging framework. It prints to the console and is minimal. Now I’m trying to integrate it into my swing/seesaw application.

(defn display-progress []
  (-> (s/frame
       :title "Progress"
       :minimum-size [640 :by 400]
       :content (s/border-panel
                 :center (s/scrollable
                          (l/log-window :id :log-window
                                        :auto-scroll? true)
                          :vscroll :always)
                 :south (s/vertical-panel
                         :items [(s/action :name "Start"
                                           :handler (fn [_] (dl/download-all-paintings)))
                                 (s/action :name "Cancel"
                                              ;; TODO Change this to something a little more graceful.
                                              ;; I just want it to stop downloading when I hit cancel.
                                           :handler (fn [_] (System/exit 1)))]))
       :on-close :dispose)
      ((fn [w] (go-loop []
                 (log-to-window w (str (async/<! log-chan) "\n"))
I’m wondering if there’s a way to make a custom publisher, that can log to a core.async channel.

Darin Douglass20:10:49

ya, publishers are pretty easy to write, just use one of the base publishers as a template:

Darin Douglass20:10:04

you can do whatever you’d like in the publish fn


(def log-chan (async/chan))

(deftype MyCustomPublisher [config buffer channel]

  (agent-buffer [_]

  (publish-delay [_]

  (publish [_ buffer]
      (doseq [item (map second (rb/items buffer))]
        (async/>! channel (str item)))
      (rb/clear buffer))))

(defn my-custom-publisher
  (MyCustomPublisher. config (rb/agent-buffer 10000) log-chan))

(def my-publisher (my-custom-publisher {}))

 {:type :multi
  :publishers [{:type :console}
               {:type :inline
                :publisher my-publisher
                :pretty-print true}]})
Alright, well I got something coming along. I just have no idea how to debug it lol.

Darin Douglass21:10:10

I’d be wary about wrapping publish (and rb/clear) in a go block: it’s already async so you can use <!! Without blocking your main thread. As for testing you should just be able to pull from the logging chan as you log stuff


@U02EA2T7FEH Thanks for that pointer. I’m still just starting to understand how core.async works.

Darin Douglass22:10:15

No worries! I’m not sure if it WILL be a problem, but I could see multiple go threads calling rb/clear at the same time or calling it with unsent messages which could cause dropped logs. So better safe than sorry I’d say :)