         ;; client -> target
         (loop []
           (when-some [client-msg (transport/recv client-transport)]
-            (log log-out :client client-msg)
+            (send write-agent log log-out :client client-msg)
             (transport/send target-transport client-msg)
             (recur)))
         (catch Exception e

              #(do (try
                     (loop []
                       (when-some [target-msg (transport/recv target-transport)]
                         (log log-out :target target-msg)
                         (transport/send client-transport target-msg)
                         (recur)))
                     (catch Exception e


(defonce print-lock (Object.))

;; using an agent so log writes don't delay messages
(defonce write-agent (agent {}))

(defn log [agent-state out from msg]
  (let [text (with-out-str (pprint msg))]
    (prn [:msg from (count text)])
    (locking print-lock
