Update 3rd-party appenders

This commit is contained in:
Peter Taoussanis 2016-06-20 18:21:58 +07:00
parent 682fa62334
commit fa1740e7fb
11 changed files with 79 additions and 74 deletions

View File

@ -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

View File

@ -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)
(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
(defn- default-entry-fn [data]
(let [{:keys [instant level hostname_
context ?err ?ns-str ?file ?line msg_]}]
{:instant instant
:level level
:?ns-str (str (:?ns-str data))
:hostname (str @(:hostname_ data))
:vargs (str @(:vargs_ data))
:?err (str @(:?err_ data))}]
: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]
[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 data congo-config))})
:fn (fn [data] (log-message collection entry-fn data))}))

View File

@ -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)))})))

View File

@ -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

View File

@ -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)})

View File

@ -33,9 +33,9 @@
{: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))}]
:content (str (force (:msg_ data)))
:error (str (:?err data))
:hostname (str (force (:hostname_ data)))}]
(ensure-conn config)
(jdbc/insert! @conn :logs entry)))

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))))}))

View File

@ -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