Skip to content

Instantly share code, notes, and snippets.

@ptaoussanis
Last active March 11, 2025 06:47
Show Gist options
  • Save ptaoussanis/f8a80f85d3e0f89b307a470ce6e044b5 to your computer and use it in GitHub Desktop.
Save ptaoussanis/f8a80f85d3e0f89b307a470ce6e044b5 to your computer and use it in GitHub Desktop.
Example of using Telemere with Bling (rich text console printing lib for Clj/s+)
;; Example created: 2024-12-23
;; Last updated: 2025-03-11 by @paintparty
;; Dependencies:
;; Telemere - Ref. https://github.com/taoensso/telemere v1.0.0-RC5 (2025-03-10)
;; Bling - Ref. https://github.com/paintparty/bling v0.5.2 (2025-03-11)
;; Platform: Clj only for now (haven't tried yet with Cljs)
;; Improvements very welcome!
;; Original context: https://github.com/taoensso/telemere/issues/33
(require '[taoensso.telemere :as tel])
(require '[taoensso.telemere.utils :as tel-utils])
(require '[bling.core :as bling])
(defn- signal->callout-opts
"Returns {:keys [type label data?]} for use with `bling/callout`, etc."
[{:keys [level]}]
(let [label (tel-utils/format-level level)
type
(case level
(:report :info) :info
(:fatal :error) :error
(:warn) :warning
(do nil))
colorway
(case level
(:trace :debug) :subtle
(do :neutral))]
{:type type,
:colorway colorway
:label label,
:data? true,
:margin-top 0,
:margin-bottom 1}))
(tel/add-handler! :my-bling-handler
(let [;; Set your preferred formatting options below as usual:
format-signal-fn (tel/format-signal-fn {:incl-newline? false})
my-output-fn
(fn [signal]
(let [norm-output (format-signal-fn signal)] ; Normal Telemere output
(bling.core/callout ; Add Bling "callout" formatting
(signal->callout-opts signal)
norm-output)))]
(tel/handler:console {:output-fn my-output-fn})))
@ptaoussanis
Copy link
Author

I just released a new version of Bling with some minor breaking changes. [...]

Sounds good 👍

I think the signal->callout-opts function in the above gist should be changed to:

Updated, thanks!

I did notice that I got no printed ouput when I set the :level to :debug like so [...] Is that the expected behavior?

Yes, that's expected since the default minimum level is :info. One can decrease the minimum level with set-min-level!, etc.

Thanks for checking on this, and for the updated gist - cheers! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment