Add support for notification levels
This commit is contained in:
parent
a5959a15c3
commit
49c1553223
2
deps.edn
2
deps.edn
|
@ -8,7 +8,7 @@
|
|||
|
||||
org.fudo/fudo-clojure {
|
||||
:git/url "https://git.fudo.org/fudo-public/fudo-clojure.git"
|
||||
:sha "9775e301714b785c27b23664b0d89e379bdca27e"
|
||||
:sha "c948aa7a8e0698fd11312832cf033d271e817e45"
|
||||
}
|
||||
}
|
||||
:aliases {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
[bebot.api.channel :as chan]
|
||||
[bebot.client :refer [connect]]
|
||||
[fudo-clojure.result :refer [let-result unwrap success]]
|
||||
[fudo-clojure.logging :as log]))
|
||||
[fudo-clojure.logging :as log :refer [level-to-int]]))
|
||||
|
||||
(defn make-logger [url access-token channel-id &
|
||||
{:keys [error-level logic-level]
|
||||
|
@ -14,3 +14,40 @@
|
|||
chan (client/open-channel! conn channel-id)]
|
||||
(success (log/log-to-function (partial chan/send-post! chan)
|
||||
error-level logic-level)))))
|
||||
|
||||
(defn make-logger [url access-token channel-id user &
|
||||
{:keys [error-level
|
||||
logic-level
|
||||
error-mention-level
|
||||
logic-mention-level]
|
||||
:or {error-level :error
|
||||
logic-level :notify
|
||||
error-mention-level :error
|
||||
logic-mention-level :notify}}]
|
||||
(let [emit (unwrap
|
||||
(let-result [conn (connect url access-token)
|
||||
channel (client/open-channel! conn channel-id)]
|
||||
(success (fn [mention msg]
|
||||
(if mention
|
||||
(chan/send-post! channel (format "@%s %s" user msg))
|
||||
(chan/send-post! channel msg))))))
|
||||
above-level? (fn [lvl] (fn [tst] (>= (level-to-int tst) (level-to-int lvl))))
|
||||
emit-error? (above-level? error-level)
|
||||
emit-logic? (above-level? logic-level)
|
||||
mention-error? (above-level? error-mention-level)
|
||||
mention-logic? (above-level? logic-mention-level)
|
||||
error-stage (fn [lvl msg]
|
||||
(when (emit-error? lvl)
|
||||
(emit (mention-error? lvl) msg)))
|
||||
logic-stage (fn [lvl msg]
|
||||
(when (logic-error? lvl)
|
||||
(emit (logic-error? lvl) msg)))]
|
||||
(reify log/Logger
|
||||
(debug! [_ msg] (error-stage :debug msg))
|
||||
(warn! [_ msg] (error-stage :warn msg))
|
||||
(error! [_ msg] (error-stage :error msg))
|
||||
(fatal! [_ msg] (error-stage :fatal msg))
|
||||
|
||||
(info! [_ msg] (logic-stage :info msg))
|
||||
(notify! [_ msg] (logic-stage :notify msg))
|
||||
(alert! [_ msg] (logic-stage :alert msg)))))
|
||||
|
|
Loading…
Reference in New Issue