Last active
March 11, 2025 06:47
-
-
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+)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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}))) |
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
Thanks for the fireworks shoutout!
I just released a new version of Bling with some minor breaking changes. I realized the interface to
bling.core/callout
around the:type
option needed some decomplecting and there is now a distinct:colorway
option that can be used if you want a colored callout that is not of type:error
:warning
or:info
(which all add labels to the top of the callout by default).I think the
signal->callout-opts
function in the above gist should be changed to:I just tested this on my side with Telemere in a
.clj
file and it seemed to work. You might want to check it on your side as this test was my first time using Telemere, so I'm not super familiar with it yet.I did notice that I got no printed ouput when I set the
:level
to:debug
like so:(tel/log! {:level :debug, :data {:foo :bar}} "Hello again!")
Also tried it in a repl, just telemere without the handler or anything:
Is that the expected behavior?
Thank you!