Liking cljdoc? Tell your friends :D

μ/log Setup Guide

μ/log logs events as data; Portal navigates data. Let's have them work together. 🤝

Using Portal to consume system logs is meant for development (and perhaps test) environments only.

The μ/log publisher defined below can be used together with other publishers, by configuring a μ/log multi publisher.

Basic Setup

Let's define a custom μ/log publisher that publishes log events with tap>:

(ns user
  (:require [com.brunobonacci.mulog :as mu]
            [com.brunobonacci.mulog.buffer :as rb]
            [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 (rb/items buffer)))]
      (tap> item))
    (rb/clear buffer)))

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

Next we start μ/log with our custom publisher:

(def pub (mu/start-publisher!
           {:type :custom, :fqn-function "user/tap-publisher"}))

What about Portal? We just hook it up as a tap, as we normally do, and the μ/logs will start flowing in.

(def p (p/open))
(add-tap #'p/submit)

(mu/log ::my-event ::ns (ns-publics *ns*))

Find a working example of this setup here.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close