Skip to content

Instantly share code, notes, and snippets.

@thomascothran
Created March 7, 2025 16:04
Show Gist options
  • Save thomascothran/c6580d503fdc98ca2a4cf99cd83447cf to your computer and use it in GitHub Desktop.
Save thomascothran/c6580d503fdc98ca2a4cf99cd83447cf to your computer and use it in GitHub Desktop.

Revisions

  1. thomascothran created this gist Mar 7, 2025.
    1 change: 1 addition & 0 deletions deps.edn
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    {:paths ["."]}
    22 changes: 22 additions & 0 deletions tap_publisher.clj
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    ;; ---------------------------------------------------------
    ;; Mulog Custom Publishers
    ;; - tap publisher for use with Portal and other tap sources
    ;; h/t Practicalli - https://practical.li/clojure/data-inspector/portal/#tap-logs-to-portal
    ;; ---------------------------------------------------------
    (ns tap-publisher
    (:require
    [com.brunobonacci.mulog.buffer :as mulog-buffer]
    [portal.api :as p]))

    (deftype TapPublisher [buffer transform]
    com.brunobonacci.mulog.publisher.PPublisher
    (agent-buffer [_] buffer)
    (publish-delay [_] 200)
    (publish [_ buffer]
    (doseq [item (transform (map second (mulog-buffer/items buffer)))]
    (tap> item))
    (mulog-buffer/clear buffer)))

    (defn tap
    [{:keys [transform] :as _config}]
    (TapPublisher. (mulog-buffer/agent-buffer 10000) (or transform identity)))