From fa1740e7fb9e28d76158b6815a0922e8c9d2607d Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Mon, 20 Jun 2016 18:21:58 +0700 Subject: [PATCH] Update 3rd-party appenders --- .../appenders/3rd_party/android_logcat.clj | 42 +++++++-------- .../timbre/appenders/3rd_party/congomongo.clj | 53 +++++++++++-------- .../timbre/appenders/3rd_party/gelf.clj | 2 +- .../timbre/appenders/3rd_party/irclj.clj | 15 +++--- .../timbre/appenders/3rd_party/logstash.clj | 3 +- .../timbre/appenders/3rd_party/postgresql.clj | 10 ++-- .../timbre/appenders/3rd_party/rolling.clj | 4 +- .../timbre/appenders/3rd_party/rotor.clj | 8 +-- .../appenders/3rd_party/server_socket.clj | 6 +-- .../timbre/appenders/3rd_party/slack.clj | 4 +- .../timbre/appenders/3rd_party/zmq.clj | 6 +-- 11 files changed, 79 insertions(+), 74 deletions(-) diff --git a/src/taoensso/timbre/appenders/3rd_party/android_logcat.clj b/src/taoensso/timbre/appenders/3rd_party/android_logcat.clj index f97ea65..bb42cf4 100644 --- a/src/taoensso/timbre/appenders/3rd_party/android_logcat.clj +++ b/src/taoensso/timbre/appenders/3rd_party/android_logcat.clj @@ -1,6 +1,6 @@ (ns taoensso.timbre.appenders.3rd-party.android-logcat "Android LogCat appender. Requires Android runtime." - {:author "Adam Clements"} + {:author "Adam Clements (@AdamClements)"} (:require [clojure.string :as str] [taoensso.timbre :as timbre])) @@ -20,34 +20,34 @@ (fn [data] (let [{:keys [level timestamp_ msg_]} data] (str - @timestamp_ " " + (force timestamp_) " " (str/upper-case (name level)) " " - @msg_))) + (force msg_)))) :fn (fn [data] - (let [{:keys [level ?ns-str ?err_ output-fn]} data - ns (str ?ns-str "") - output-str (output-fn data)] + (let [{:keys [level ?ns-str ?err output_]} data + ns-str (str ?ns-str "") + output-str (force output_)] - (if-let [throwable @?err_] + (if-let [err ?err] (case level - :trace (android.util.Log/d ns output-str throwable) - :debug (android.util.Log/d ns output-str throwable) - :info (android.util.Log/i ns output-str throwable) - :warn (android.util.Log/w ns output-str throwable) - :error (android.util.Log/e ns output-str throwable) - :fatal (android.util.Log/e ns output-str throwable) - :report (android.util.Log/i ns output-str throwable)) + :trace (android.util.Log/d ns-str output-str err) + :debug (android.util.Log/d ns-str output-str err) + :info (android.util.Log/i ns-str output-str err) + :warn (android.util.Log/w ns-str output-str err) + :error (android.util.Log/e ns-str output-str err) + :fatal (android.util.Log/e ns-str output-str err) + :report (android.util.Log/i ns-str output-str err)) (case level - :trace (android.util.Log/d ns output-str) - :debug (android.util.Log/d ns output-str) - :info (android.util.Log/i ns output-str) - :warn (android.util.Log/w ns output-str) - :error (android.util.Log/e ns output-str) - :fatal (android.util.Log/e ns output-str) - :report (android.util.Log/i ns output-str)))))}) + :trace (android.util.Log/d ns-str output-str) + :debug (android.util.Log/d ns-str output-str) + :info (android.util.Log/i ns-str output-str) + :warn (android.util.Log/w ns-str output-str) + :error (android.util.Log/e ns-str output-str) + :fatal (android.util.Log/e ns-str output-str) + :report (android.util.Log/i ns-str output-str)))))}) ;;;; Deprecated diff --git a/src/taoensso/timbre/appenders/3rd_party/congomongo.clj b/src/taoensso/timbre/appenders/3rd_party/congomongo.clj index 23128f9..788a878 100644 --- a/src/taoensso/timbre/appenders/3rd_party/congomongo.clj +++ b/src/taoensso/timbre/appenders/3rd_party/congomongo.clj @@ -1,30 +1,37 @@ (ns taoensso.timbre.appenders.3rd-party.congomongo "MongoDB appender. Requires on https://github.com/aboekhoff/congomongo." - {:author "Emlyn Corrin"} + {:author "Emlyn Corrin (@emlyn)"} (:require [somnium.congomongo :as mongo] [taoensso.timbre :as timbre] [taoensso.encore :as encore])) ;; TODO Test port to Timbre v4 -(def default-args {:host "127.0.0.1" :port 27017}) -(defn connect [{:keys [db server write-concern]}] - (let [args (merge default-args server) - c (mongo/make-connection db args)] +(defn- connect [{:keys [db server write-concern]}] + (let [args (merge {:host "127.0.0.1" :port 27017} server) + c (mongo/make-connection db args)] (when write-concern (mongo/set-write-concern c write-concern)) c)) -(def conn (atom nil)) -(defn ensure-conn [config] (swap! conn #(or % (connect config)))) +(def ^:private conn_ (atom nil)) +(defn- ensure-conn [config] (swap! conn_ #(or % (connect config)))) -(defn log-message [params {:keys [collection logged-keys] :as config}] - (let [entry {:instant instant - :level level - :?ns-str (str (:?ns-str data)) - :hostname (str @(:hostname_ data)) - :vargs (str @(:vargs_ data)) - :?err (str @(:?err_ data))}] +(defn- default-entry-fn [data] + (let [{:keys [instant level hostname_ + context ?err ?ns-str ?file ?line msg_]}] + {:instant instant + :level level + :hostname (force hostname_) + :context context + :?err (when-let [err ?err] (str err)) + :?ns-str ?ns-str + :?file ?file + :?line ?line + :msg (force msg_)})) + +(defn- log-message [collection entry-fn data] + (let [entry (entry-fn data)] (mongo/with-mongo (ensure-conn config) (mongo/insert! collection entry)))) @@ -33,15 +40,15 @@ (congomongo-appender {:db \"logs\" :collection \"myapp\" - :logged-keys [:instant :level :msg_] :write-concern :acknowledged :server {:host \"127.0.0.1\" :port 27017}})" - - [congo-config] - {:enabled? true - :async? true - :min-level :warn - :rate-limit [[1 1000]] ; 1/sec - :output-fn :inherit - :fn (fn [data] (log-message data congo-config))}) + [config] + (let [{:keys [collection entry-fn] + :or {entry-fn default-entry-fn}} config] + {:enabled? true + :async? true + :min-level :warn + :rate-limit [[1 1000]] ; 1/sec + :output-fn :inherit + :fn (fn [data] (log-message collection entry-fn data))})) diff --git a/src/taoensso/timbre/appenders/3rd_party/gelf.clj b/src/taoensso/timbre/appenders/3rd_party/gelf.clj index 71c43ef..fe91586 100644 --- a/src/taoensso/timbre/appenders/3rd_party/gelf.clj +++ b/src/taoensso/timbre/appenders/3rd_party/gelf.clj @@ -52,6 +52,6 @@ (let [{:keys [appender msg_ level hostname_]} data gelf-transport (:gelf-transport appender) log-level (timbre-to-gelf-level level) - gelf-message (-> (GelfMessageBuilder. @msg_ @hostname_) + gelf-message (-> (GelfMessageBuilder. (force msg_) (force hostname_)) (.level log-level) .build)] (.send gelf-transport gelf-message)))}))) diff --git a/src/taoensso/timbre/appenders/3rd_party/irclj.clj b/src/taoensso/timbre/appenders/3rd_party/irclj.clj index 0e2d392..d425ac7 100644 --- a/src/taoensso/timbre/appenders/3rd_party/irclj.clj +++ b/src/taoensso/timbre/appenders/3rd_party/irclj.clj @@ -1,6 +1,6 @@ (ns taoensso.timbre.appenders.3rd-party.irclj "IRC appender. Requires https://github.com/flatland/irclj." - {:author "Emlyn Corrin"} + {:author "Emlyn Corrin (@emlyn)"} (:require [clojure.string :as str] [irclj.core :as irc] [taoensso.timbre :as timbre])) @@ -34,8 +34,7 @@ :name \"My Logger\" :chan \"#logs\"})" [irc-config] - (let [conn (atom nil) - fmt-fn (or (:fmt-output-fn irc-config) default-fmt-output-fn)] + (let [conn (atom nil)] {:enabled? true :async? true :min-level :info @@ -43,19 +42,19 @@ :output-fn (fn [data] - (let [{:keys [level ?err_ msg_]}] + (let [{:keys [level ?err msg_]} data] (format "[%s] %s%s" (-> level name (str/upper-case)) - (or @msg_ "") - (if-let [err @?err_] + (or (force msg_) "") + (if-let [err ?err] (str "\n" (timbre/stacktrace err)) "")))) :fn (fn [data] - (let [{:keys [output-fn]} data] + (let [{:keys [output_]} data] (ensure-conn conn irc-config) - (send-message conn (:chan irc-config) (output-fn data))))})) + (send-message conn (:chan irc-config) (force output_))))})) ;;;; Deprecated diff --git a/src/taoensso/timbre/appenders/3rd_party/logstash.clj b/src/taoensso/timbre/appenders/3rd_party/logstash.clj index 380d7f8..f93e3b6 100644 --- a/src/taoensso/timbre/appenders/3rd_party/logstash.clj +++ b/src/taoensso/timbre/appenders/3rd_party/logstash.clj @@ -1,6 +1,5 @@ (ns taoensso.timbre.appenders.3rd-party.logstash "Timbre appender that send output to logstash. - Requires cheshire (https://github.com/dakrone/cheshire)." {:author "Mike Sperber (@mikesperber), David Frese (@dfrese)"} (:require [taoensso.timbre :as timbre] @@ -37,7 +36,7 @@ :namespace (:?ns-str data) :file (:?file data) :line (:?line data) - :stacktrace (some-> (force (:?err_ data)) (stacktrace-str)) + :stacktrace (some-> (:?err data) (stacktrace-str)) :hostname (force (:hostname_ data)) :message (force (:msg_ data)) "@timestamp" (:instant data)}) diff --git a/src/taoensso/timbre/appenders/3rd_party/postgresql.clj b/src/taoensso/timbre/appenders/3rd_party/postgresql.clj index ea48c89..cc8498c 100644 --- a/src/taoensso/timbre/appenders/3rd_party/postgresql.clj +++ b/src/taoensso/timbre/appenders/3rd_party/postgresql.clj @@ -31,11 +31,11 @@ (defn log-message [config data] (let [entry {:instant (java.sql.Timestamp. (.getTime ^java.util.Date (:instant data))) - :level (str (:level data)) - :namespace (str (:?ns-str data)) - :hostname (str @(:hostname_ data)) - :content (str @(:vargs_ data)) - :error (str @(:?err_ data))}] + :level (str (:level data)) + :namespace (str (:?ns-str data)) + :content (str (force (:msg_ data))) + :error (str (:?err data)) + :hostname (str (force (:hostname_ data)))}] (ensure-conn config) (jdbc/insert! @conn :logs entry))) diff --git a/src/taoensso/timbre/appenders/3rd_party/rolling.clj b/src/taoensso/timbre/appenders/3rd_party/rolling.clj index dbb74f6..71b42c9 100644 --- a/src/taoensso/timbre/appenders/3rd_party/rolling.clj +++ b/src/taoensso/timbre/appenders/3rd_party/rolling.clj @@ -56,8 +56,8 @@ :output-fn :inherit :fn (fn [data] - (let [{:keys [instant output-fn]} data - output-str (output-fn data) + (let [{:keys [instant output_]} data + output-str (force output_) prev-cal (prev-period-end-cal instant pattern)] (when-let [log (io/file path)] (try diff --git a/src/taoensso/timbre/appenders/3rd_party/rotor.clj b/src/taoensso/timbre/appenders/3rd_party/rotor.clj index d9fd151..8bb5e1c 100644 --- a/src/taoensso/timbre/appenders/3rd_party/rotor.clj +++ b/src/taoensso/timbre/appenders/3rd_party/rotor.clj @@ -1,5 +1,5 @@ (ns taoensso.timbre.appenders.3rd-party.rotor - {:author "Karsten Schmidt"} + {:author "Karsten Schmidt (@postspectacular)"} (:require [clojure.java.io :as io] [taoensso.timbre :as timbre]) (:import [java.io File FilenameFilter])) @@ -57,8 +57,8 @@ :fn (let [lock (Object.)] (fn [data] - (let [{:keys [output-fn]} data - output-str (output-fn data)] + (let [{:keys [output_]} data + output-str (str (force output_) "\n")] (let [log (io/file path)] (try ;; all the filesystem manipulations are unsafe in the face of concurrency @@ -67,7 +67,7 @@ (io/make-parents log)) (when (> (.length log) max-size) (rotate-logs path backlog))) - (spit path (str (output-fn data) "\n") :append true) + (spit path output-str :append true) (catch java.io.IOException _))))))}) ;;;; Deprecated diff --git a/src/taoensso/timbre/appenders/3rd_party/server_socket.clj b/src/taoensso/timbre/appenders/3rd_party/server_socket.clj index 32bde3e..4a8761b 100644 --- a/src/taoensso/timbre/appenders/3rd_party/server_socket.clj +++ b/src/taoensso/timbre/appenders/3rd_party/server_socket.clj @@ -1,6 +1,6 @@ (ns taoensso.timbre.appenders.3rd-party.server-socket "TCP socket appender. Requires https://github.com/technomancy/server-socket." - {:author "Emlyn Corrin"} + {:author "Emlyn Corrin (@emlyn)"} (:require [server.socket :refer [create-server]] [taoensso.timbre :refer [stacktrace]]) (:import [java.net Socket InetAddress] @@ -45,12 +45,12 @@ :output-fn :inherit :fn (fn [data] - (let [{:keys [output-fn]} data] + (let [{:keys [output_]} data] (let [c (ensure-conn socket-config)] (doseq [sock @(:connections c)] (let [out (PrintWriter. (.getOutputStream ^Socket sock))] (binding [*out* out] - (println (output-fn data))))))))})) + (println (force output_))))))))})) ;;;; Deprecated diff --git a/src/taoensso/timbre/appenders/3rd_party/slack.clj b/src/taoensso/timbre/appenders/3rd_party/slack.clj index 1f52b18..7f9cdb6 100644 --- a/src/taoensso/timbre/appenders/3rd_party/slack.clj +++ b/src/taoensso/timbre/appenders/3rd_party/slack.clj @@ -25,6 +25,6 @@ :output-fn :inherit :fn (fn [data] - (let [{:keys [output-fn]} data] - (slack.chat/post-message conn channel (output-fn data) + (let [{:keys [output_]} data] + (slack.chat/post-message conn channel (force output_) (dissoc opts :token :channel))))})) diff --git a/src/taoensso/timbre/appenders/3rd_party/zmq.clj b/src/taoensso/timbre/appenders/3rd_party/zmq.clj index 80493eb..93ff710 100644 --- a/src/taoensso/timbre/appenders/3rd_party/zmq.clj +++ b/src/taoensso/timbre/appenders/3rd_party/zmq.clj @@ -1,6 +1,6 @@ (ns taoensso.timbre.appenders.3rd-party.zmq "ØMQ appender. Requires https://github.com/zeromq/cljzmq" - {:author "Angus Fletcher"} + {:author "Angus Fletcher (@angusiguess)"} (:require [zeromq.zmq :as zmq] [taoensso.timbre :as timbre])) @@ -27,8 +27,8 @@ :output-fn :inherit :fn (fn [data] - (let [{:keys [output-fn]} data - output-str (output-fn data)] + (let [{:keys [output_]} data + output-str (force output_)] (loop [] (zmq/poll poller 500) (cond