From 5797696fbf3ac2065351a220ec32b3bf00cd5291 Mon Sep 17 00:00:00 2001 From: Angus Fletcher Date: Wed, 7 May 2014 17:28:28 -0300 Subject: [PATCH] Add zmq appender (@angusiguess) --- src/taoensso/timbre/appenders/zmq.clj | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/taoensso/timbre/appenders/zmq.clj diff --git a/src/taoensso/timbre/appenders/zmq.clj b/src/taoensso/timbre/appenders/zmq.clj new file mode 100644 index 0000000..056ec0b --- /dev/null +++ b/src/taoensso/timbre/appenders/zmq.clj @@ -0,0 +1,34 @@ +(ns taoensso.timbre.appenders.zmq + "ØMQ appender. Requires https://github.com/zeromq/cljzmq" + {:author "Angus Fletcher"} + (:require [zeromq.zmq :as zmq] + [taoensso.timbre :as timbre])) + +(defn make-zmq-socket [context transport address port] + (doto (zmq/socket context :push) + (zmq/connect (format "%s://%s:%d" transport address port)))) + +(defn appender-fn [socket poller {:keys [ap-config output]}] + (loop [] + (zmq/poll poller 500) + (cond + (zmq/check-poller poller 0 :pollout) (zmq/send-str socket output) + (zmq/check-poller poller 0 :pollerr) (System/exit 1) + :else (recur)))) + +(defn make-zmq-appender + "Returns a ØMQ appender. Takes appender options and a map consisting of: + transport: a string representing transport type: tcp, ipc, inproc, pgm/epgm + address: a string containing an address to connect to. + port: a number representing the port to connect to." + [& [appender-opts {:keys [transport address port]}]] + (let [default-appender-opts {:enabled? true + :min-level :error + :async? true} + context (zmq/zcontext) + socket (make-zmq-socket context transport address port) + poller (doto (zmq/poller context) + (zmq/register socket :pollout :pollerr))] + (merge default-appender-opts + appender-opts + {:fn (partial appender-fn socket poller)})))