|
| 1 | +# Mulog |
| 2 | + |
| 3 | +Mulog is an fast and flexible event log library with a wide range of log publisher (Cloudwatch, ..., etc.) |
| 4 | + |
| 5 | +!!! EXAMPLE "Mulog events publisher" |
| 6 | + ```clojure title="dev/mulog_events.clj" |
| 7 | + ;; --------------------------------------------------------- |
| 8 | + ;; Mulog Global Context and Custom Publisher |
| 9 | + ;; |
| 10 | + ;; - set event log global context |
| 11 | + ;; - tap publisher for use with Portal and other tap sources |
| 12 | + ;; - publish all mulog events to Portal tap source |
| 13 | + ;; --------------------------------------------------------- |
| 14 | + |
| 15 | + (ns mulog-events |
| 16 | + (:require |
| 17 | + [com.brunobonacci.mulog :as mulog] |
| 18 | + [com.brunobonacci.mulog.buffer :as mulog-buffer])) |
| 19 | + |
| 20 | + ;; --------------------------------------------------------- |
| 21 | + ;; Set event global context |
| 22 | + ;; - information added to every event for REPL workflow |
| 23 | + (mulog/set-global-context! {:app-name "todo-tracker Service", |
| 24 | + :version "0.1.0", :env "dev"}) |
| 25 | + ;; --------------------------------------------------------- |
| 26 | + |
| 27 | + ;; --------------------------------------------------------- |
| 28 | + ;; Mulog event publishing |
| 29 | + |
| 30 | + (deftype TapPublisher |
| 31 | + [buffer transform] |
| 32 | + com.brunobonacci.mulog.publisher.PPublisher |
| 33 | + (agent-buffer [_] buffer) |
| 34 | + (publish-delay [_] 200) |
| 35 | + (publish [_ buffer] |
| 36 | + (doseq [item (transform (map second (mulog-buffer/items buffer)))] |
| 37 | + (tap> item)) |
| 38 | + (mulog-buffer/clear buffer))) |
| 39 | + |
| 40 | + #_{:clj-kondo/ignore [:unused-private-var]} |
| 41 | + (defn ^:private tap-events |
| 42 | + [{:keys [transform] :as _config}] |
| 43 | + (TapPublisher. (mulog-buffer/agent-buffer 10000) (or transform identity))) |
| 44 | + |
| 45 | + (def tap-publisher |
| 46 | + "Start mulog custom tap publisher to send all events to Portal |
| 47 | + and other tap sources |
| 48 | + `mulog-tap-publisher` to stop publisher" |
| 49 | + (mulog/start-publisher! |
| 50 | + {:type :custom, :fqn-function "mulog-events/tap-events"})) |
| 51 | + |
| 52 | + #_{:clj-kondo/ignore [:unused-public-var]} |
| 53 | + (defn stop |
| 54 | + "Stop mulog tap publisher to ensure multiple publishers are not started |
| 55 | + Recommended before using `(restart)` or evaluating the `user` namespace" |
| 56 | + [] |
| 57 | + tap-publisher) |
| 58 | + |
| 59 | + ;; Example mulog event message |
| 60 | + ;; (mulog/log ::dev-user-ns :message "Example event message" :ns (ns-publics *ns*)) |
| 61 | + ;; --------------------------------------------------------- |
| 62 | + ``` |
| 63 | + |
0 commit comments