Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log viewer requires :result key and does not accept java.time.Instant as :time #258

Open
Ramblurr opened this issue Feb 27, 2025 · 0 comments

Comments

@Ramblurr
Copy link

Ramblurr commented Feb 27, 2025

I was trying to turn telemere signals into maps that were suitable for display with :portal.viewer/log and ran in to several problems:

  1. The :result key is required, even the the predicate spec doesn't list it, if you do not pass it the viewer breaks.
  2. The :time predicate is inst?, which java.time.Instant passes. But if you pass a java.time.Instant as :time, the viewer breaks.

By "breaks" I mean the viewer falls back to the inspector viewer, I never actually saw any error messages.

Here is a working config I landed on:

(require '[taoensso.telemere :as taoensso.telemere])
(defn telemere->tap
  ([{:keys [msg_ level inst] :as signal}]
   (tap>
    (with-meta
      (->
       ;; remove a bunch of nil values
       (into {} (remove #(nil? (val %))) signal)
       ;; add result which the portal viewer will use to display the log message
       (assoc :result [level msg_])
       ;; viewer doesn't support java.time.Instant
       (assoc :time (java.util.Date/from inst))
       (dissoc :inst)
       ;; telemere provides ns as a string, but viewer wants a symbol
       (update :ns  symbol)
       ;; add in runtime to get a nice logo
       (assoc :runtime ((requiring-resolve 'portal.console/runtime))))
      {:portal.viewer/default :portal.viewer/log
       :portal.viewer/for
       {:form :portal.viewer/pprint
        :time :portal.viewer/relative-time}})))
  ([]
   (tap> [:signal "telemere handler has shut down"])))

(defn add-telemere-tap-handler! []
  (taoensso.telemere/remove-handler! :tap-handler)
  (taoensso.telemere/add-handler! :tap-handler telemere->tap
                                                       {:min-level :debug}))

(do
  (add-telemere-tap-handler!)
  (taoensso.telemere/log! {:level :error :data {:err "Exception"}} "Error oh noes!")
  (taoensso.telemere/log! {:level :info :data {:interesting :fact}} "Did you know that..")
  (taoensso.telemere/log! {:level :debug :data {:data [42]}} "datadatatatadatatatata"))

Screenshots

Image

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant