Last active
December 31, 2024 09:20
-
-
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: 2024-12-23 | |
;; Dependencies: | |
;; Telemere - Ref. https://github.com/taoensso/telemere v1.0.0-RC2 (2024-10-29) | |
;; Bling - Ref. https://github.com/paintparty/bling v0.4.2 (2024-11-20) | |
;; 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 | |
(:fatal :error) :error | |
(:warn) :warning | |
(:trace :debug) :subtle | |
(do :neutral))] | |
{:type type, :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}))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note also https://github.com/paintparty/fireworks from the same author as Bling 👍