[nop] Update to Truss v2

This commit is contained in:
Peter Taoussanis 2025-02-26 16:24:15 +01:00
parent 97efef3d40
commit 2c5599c234
15 changed files with 127 additions and 116 deletions

View file

@ -10,7 +10,8 @@
:scm {:name "git" :url "https://github.com/taoensso/telemere"}
:dependencies
[[com.taoensso/encore "3.132.0"]]
[[com.taoensso/truss "2.0.0-SNAPSHOT"]
[com.taoensso/encore "3.132.0"]]
:test-paths ["test" #_"src"]

View file

@ -7,7 +7,8 @@
{:author "Peter Taoussanis (@ptaoussanis)"}
(:refer-clojure :exclude [newline])
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere.impl :as impl]
[taoensso.telemere.utils :as utils]
@ -166,7 +167,7 @@
;; Via SDK autoconfiguration extension (when available)
(enc/compile-when
io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk
(enc/catching :common
(truss/catching :common
(let [builder (io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk/builder)
sdk (.getOpenTelemetrySdk (.build builder))]
{:logger-provider (.getLogsBridge sdk)
@ -272,7 +273,7 @@
(impl/signal! ~(assoc opts :error gs-error))
(do ~gs-error)))))))
(comment (with-signal (throw (error! ::my-id (ex-info "MyEx" {})))))
(comment (with-signal (throw (error! ::my-id (truss/ex-info "MyEx" {})))))
#?(:clj
(let [base-opts {:kind :error, :level :error}]
@ -289,7 +290,7 @@
opts (dissoc opts :run :catch-val)
gs-caught (gensym "caught")]
`(enc/try* ~run-form
`(truss/try* ~run-form
(catch :all ~gs-caught
(impl/signal! ~(assoc opts :error gs-caught))
(if ~rethrow? (throw ~gs-caught) ~catch-val))))))))
@ -400,9 +401,9 @@
(add-handler! :default/console (handler:console))
#?(:clj (enc/catching (require '[taoensso.telemere.tools-logging]))) ; TL->Telemere
#?(:clj (enc/catching (require '[taoensso.telemere.slf4j]))) ; SLF4J->Telemere
#?(:clj (enc/catching (require '[taoensso.telemere.open-telemetry]))) ; Telemere->OTel
#?(:clj (truss/catching (require '[taoensso.telemere.tools-logging]))) ; TL->Telemere
#?(:clj (truss/catching (require '[taoensso.telemere.slf4j]))) ; SLF4J->Telemere
#?(:clj (truss/catching (require '[taoensso.telemere.open-telemetry]))) ; Telemere->OTel
)
;;;; Flow benchmarks
@ -467,8 +468,8 @@
(event! ::ev-id
{:data {:a :A :b :b}
:error
(ex-info "Ex2" {:b :B}
(ex-info "Ex1" {:a :A}))}))]
(truss/ex-info "Ex2" {:b :B}
(truss/ex-info "Ex1" {:a :A}))}))]
(do (let [hf (handler:file)] (hf sig) (hf)))
(do (let [hf (handler:console)] (hf sig) (hf)))

View file

@ -2,7 +2,8 @@
"Private ns, implementation detail.
Core console handlers, aliased in main Telemere ns."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.utils :as utils]))
(comment
@ -126,7 +127,7 @@
(.group js/console (preamble-fn signal))
(content-fn signal (logger-fn logger) identity)
(when-let [stack (and error (.-stack (enc/ex-root error)))]
(when-let [stack (and error (.-stack (truss/ex-root error)))]
(.call logger logger stack))
(.groupEnd js/console)))))))))

View file

@ -2,7 +2,8 @@
"Private ns, implementation detail.
Core file handler, aliased in main Telemere ns."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.utils :as utils]))
(comment
@ -71,9 +72,9 @@
:daily (str (.format dtf (java.time.LocalDate/ofEpochDay edy)) "d")
:weekly (str (.format dtf (java.time.LocalDate/ofEpochDay (edy-week edy))) "w")
:monthly (str (.format dtf (java.time.LocalDate/ofEpochDay (edy-month edy))) "m")
(enc/unexpected-arg! interval
{:context `file-timestamp
:param 'interval
(truss/unexpected-arg! interval
{:param 'interval
:context `file-timestamp
:expected #{:daily :weekly :monthly}}))))
(comment (file-timestamp->edy (format-file-timestamp :weekly (udt->edy (enc/now-udt*)))))
@ -81,7 +82,7 @@
(defn manage-test-files!
"Describes/creates/deletes files used for tests/debugging, etc."
[action]
(have? [:el #{:return :println :create :delete}] action)
(truss/have? [:el #{:return :println :create :delete}] action)
(let [fnames_ (volatile! [])
action!
(fn [app timestamp part gz? timestamp main?]
@ -136,7 +137,7 @@
- Have the same `interval` type #{:daily :weekly :monthly nil} (=> ?timestamped).
- Have the given timestamp (e.g. \"2020-01-01d\", or nil for NO timestamp)."
[main-path interval timestamp sort?]
(have? [:el #{:daily :weekly :monthly nil}] interval)
(truss/have? [:el #{:daily :weekly :monthly nil}] interval)
(let [main-file (utils/as-file main-path) ; `logs/app.log`
main-dir (.getParentFile (.getAbsoluteFile main-file)) ; `.../logs`
@ -168,9 +169,8 @@
(let [actual (.getAbsolutePath file-in)
expected file-name]
(when-not (.endsWith actual expected)
(throw
(ex-info "Unexpected file name"
{:actual actual, :expected expected}))))
(truss/ex-info! "Unexpected file name"
{:actual actual, :expected expected})))
(conj acc
{:file file-in
@ -234,8 +234,8 @@
arch-file+gz (utils/as-file arch-file-name+gz) ; `logs/app.log.1.gz` or `logs/app.log-2020-01-01d.1.gz`
]
(have? false? (.exists arch-file+gz)) ; No pre-existing `.1.gz`
(.renameTo main-file arch-file-gz)
(truss/have? false? (.exists arch-file+gz)) ; No pre-existing `.1.gz`
(.renameTo main-file arch-file-gz)
(.createNewFile main-file)
(when gz?

View file

@ -3,7 +3,8 @@
Signal design shared by: Telemere, Tufte, Timbre."
(:require
[clojure.set :as set]
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs])
#?(:cljs
@ -169,7 +170,7 @@
(defn default-trace-msg
[form value error nsecs]
(if error
(str form " !> " (enc/ex-type error))
(str form " !> " (truss/ex-type error))
(str form " => " value)))
(comment
@ -232,7 +233,7 @@
:server io.opentelemetry.api.trace.SpanKind/SERVER
:consumer io.opentelemetry.api.trace.SpanKind/CONSUMER
:producer io.opentelemetry.api.trace.SpanKind/PRODUCER
(enc/unexpected-arg! ?span-kind
(truss/unexpected-arg! ?span-kind
{:expected #{nil :internal :client :server :consumer :producer}})))
(.with ^io.opentelemetry.context.Context parent-context
@ -327,7 +328,7 @@
([raw-msg? trap-signals? form]
`(let [sig_# (volatile! nil)]
(binding [*sig-spy* (SpyOpts. sig_# true ~trap-signals?)]
(enc/try* ~form (catch :all _#)))
(truss/try* ~form (catch :all _#)))
(if ~raw-msg?
(do @sig_#)
@ -348,7 +349,7 @@
`(let [sigs_# (volatile! nil)
base-map#
(binding [*sig-spy* (SpyOpts. sigs_# false ~trap-signals?)]
(enc/try*
(truss/try*
(do {:value ~form})
(catch :all t# {:error t#})))
@ -477,7 +478,7 @@
sample-rate kind ns id level when rate-limit rate-limit-by,
ctx ctx+ parent root trace?, do let data msg error #_run & kvs]}])
(enc/unexpected-arg! macro-id))))
(truss/unexpected-arg! macro-id))))
;;;; Signal macro
@ -486,12 +487,11 @@
(#?(:clj invoke :cljs -invoke) [_] (if error (throw error) value))
(#?(:clj invoke :cljs -invoke) [_ signal_]
(if error
(throw
(ex-info "Signal `:run` form error"
(enc/try*
(do {:taoensso.telemere/signal (force signal_)})
(catch :all t {:taoensso.telemere/signal-error t}))
error))
(truss/ex-info! "Signal `:run` form error"
(truss/try*
(do {:taoensso.telemere/signal (force signal_)})
(catch :all t {:taoensso.telemere/signal-error t}))
error)
value)))
(defn inst+nsecs
@ -506,10 +506,9 @@
(defn- valid-opts! [x]
(if (map? x)
(do x)
(throw
;; We require const map keys, but vals may require eval
(ex-info "Telemere signal opts must be a map with const (compile-time) keys."
{:opts (enc/typed-val x)})))))
;; We require const map keys, but vals may require eval
(truss/ex-info! "Telemere signal opts must be a map with const (compile-time) keys."
{:opts (truss/typed-val x)}))))
#?(:clj (defn- auto-> [form auto-form] (if (= form :auto) auto-form form)))
#?(:clj
@ -565,9 +564,10 @@
trace? (get opts :trace? (boolean run-form))
_
(when-not (contains? #{true false nil} trace?)
(enc/unexpected-arg! trace?
{:msg "Expected constant (compile-time) `:trace?` boolean"
:context `signal!}))
(truss/unexpected-arg! trace?
{:param 'trace?
:context `signal!
:msg "Expected constant (compile-time) `:trace?` boolean"}))
thread-form (when clj? `(enc/thread-info))
@ -611,17 +611,15 @@
_ ; Compile-time validation
(do
(when (and run-form error-form) ; Ambiguous source of error
(throw
(ex-info "Signals cannot have both `:run` and `:error` opts at the same time"
{:run-form run-form
:error-form error-form
:location location
:other-opts (dissoc opts :run :error)})))
(truss/ex-info! "Signals cannot have both `:run` and `:error` opts at the same time"
{:run-form run-form
:error-form error-form
:location location
:other-opts (dissoc opts :run :error)}))
(when-let [e (find opts :msg_)] ; Common typo/confusion
(throw
(ex-info "Signals cannot have `:msg_` opt (did you mean `:msg`?))"
{:msg_ (enc/typed-val (val e))}))))
(truss/ex-info! "Signals cannot have `:msg_` opt (did you mean `:msg`?))"
{:msg_ (truss/typed-val (val e))})))
signal-form
(let [record-form
@ -631,7 +629,7 @@
[:run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~'_msg_, ~'_run-err '~show-run-form ~show-run-val ~'_end-inst ~'_run-nsecs)
[:no-run :clj ] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, (enc/host-info) ~'__thread ~'__otel-context1, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
[:no-run :cljs] `(Signal. 1 ~'__inst ~'__uid, ~location ~'__ns ~line-form ~column-form ~file-form, ~sample-rate-form, ~'__kind ~'__id ~'__level, ~ctx-form ~parent-form ~'__root1, ~data-form ~kvs-form ~msg-form, ~error-form nil nil nil nil)
(enc/unexpected-arg! clause {:context :signal-constructor-args})))
(truss/unexpected-arg! clause {:context :signal-constructor-args})))
record-form
(if-not run-form
@ -678,7 +676,7 @@
~'__run-result
~(when run-form
`(let [t0# (enc/now-nano*)]
(enc/try*
(truss/try*
(do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#)))
(catch :all t# (RunResult. nil t# (- (enc/now-nano*) t0#))))))]
@ -692,7 +690,7 @@
`(binding [*trace-root* ~'__root1
*trace-parent* {:id ~'__id, :uid ~'__uid}]
(let [t0# (enc/now-nano*)]
(enc/try*
(truss/try*
(do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#)))
(catch :all t# (RunResult. nil t# (- (enc/now-nano*) t0#)))))))]
@ -713,7 +711,7 @@
*trace-parent* {:id ~'__id, :uid ~'__uid}]
(let [otel-scope# (.makeCurrent ~'__otel-context1)
t0# (enc/now-nano*)]
(enc/try*
(truss/try*
(do (RunResult. ~run-form* nil (- (enc/now-nano*) t0#)))
(catch :all t# (RunResult. nil t# (- (enc/now-nano*) t0#)))
(finally (.close otel-scope#))))))])

View file

@ -5,7 +5,8 @@
(:require
[clojure.string :as str]
[clojure.set :as set]
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.utils :as utils]
[taoensso.telemere.impl :as impl]
[taoensso.telemere :as tel])
@ -61,24 +62,24 @@
clojure.lang.IPersistentCollection
(-put-attr! [v ^String k ^AttributesBuilder ab]
(if (map? v)
(when-let [^String s (enc/catching :common (enc/pr-edn* v))]
(when-let [^String s (truss/catching :common (enc/pr-edn* v))]
(.put ab k s))
(when-some [v1 (if (indexed? v) (nth v 0 nil) (first v))]
(or
(cond
(string? v1) (enc/catching :common (.put ab k ^"[Ljava.lang.String;" (into-array String v)))
(int? v1) (enc/catching :common (.put ab k (long-array v)))
(float? v1) (enc/catching :common (.put ab k (double-array v)))
(boolean? v1) (enc/catching :common (.put ab k (boolean-array v))))
(string? v1) (truss/catching :common (.put ab k ^"[Ljava.lang.String;" (into-array String v)))
(int? v1) (truss/catching :common (.put ab k (long-array v)))
(float? v1) (truss/catching :common (.put ab k (double-array v)))
(boolean? v1) (truss/catching :common (.put ab k (boolean-array v))))
(when-let [^String s (enc/catching :common (enc/pr-edn* v))]
(when-let [^String s (truss/catching :common (enc/pr-edn* v))]
(.put ab k s)))))
ab)
Object
(-put-attr! [v ^String k ^AttributesBuilder ab]
(when-let [^String s (enc/catching :common (enc/pr-edn* v))]
(when-let [^String s (truss/catching :common (enc/pr-edn* v))]
(.put ab k s))))
(defmacro ^:private put-attr! [attrs-builder attr-name attr-val]
@ -90,8 +91,9 @@
(map? attrs) (enc/run-kv! (fn [k v] (put-attr! attrs-builder (attr-name k) v)) attrs) ; Unprefixed
(instance? Attributes attrs) (.putAll attrs-builder ^Attributes attrs) ; Unprefixed
:else
(enc/unexpected-arg! attrs
{:context `put-attrs!
(truss/unexpected-arg! attrs
{:param 'attrs
:context `put-attrs!
:expected #{nil map io.opentelemetry.api.common.Attributes}})))
(defn- merge-attrs!
@ -145,7 +147,7 @@
(put-attr! ab "level" ; Standard
(level->string level)))
(when-let [{:keys [type msg trace data]} (enc/ex-map (get signal :error))]
(when-let [{:keys [type msg trace data]} (truss/ex-map (get signal :error))]
(put-attr! ab "exception.type" type) ; Standard
(put-attr! ab "exception.message" msg) ; Standard
(when trace
@ -356,7 +358,7 @@
(force msg_)
(when-let [error (get signal :error)]
(when (instance? Throwable error)
(str (enc/ex-type error) ": " (enc/ex-message error)))))]
(str (truss/ex-type error) ": " (ex-message error)))))]
(.setBody lrb body))
;; Emit to `LogRecordExporter`

View file

@ -2,6 +2,7 @@
"Email handler using `postal`,
Ref. <https://github.com/drewr/postal>."
(:require
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere.utils :as utils]
@ -76,8 +77,8 @@
subject-fn (utils/signal-preamble-fn {:format-inst-fn nil})
subject-max-len 128}}]
(when-not (map? conn-opts) (throw (ex-info "Expected `:conn-opts` map" (enc/typed-val conn-opts))))
(when-not (map? msg-opts) (throw (ex-info "Expected `:msg-opts` map" (enc/typed-val msg-opts))))
(when-not (map? conn-opts) (truss/ex-info! "Expected `:conn-opts` map" (truss/typed-val conn-opts)))
(when-not (map? msg-opts) (truss/ex-info! "Expected `:msg-opts` map" (truss/typed-val msg-opts)))
(let [subject-fn
(if-let [n subject-max-len]
@ -108,7 +109,7 @@
success? (= (get result :code) 0)]
(when-not success?
(throw (ex-info "Failed to send email" result ex)))))))]
(truss/ex-info! "Failed to send email" result ex))))))]
(with-meta handler-fn
{:dispatch-opts default-dispatch-opts}))))

View file

@ -2,7 +2,8 @@
"Slack handler using `clj-slack`,
Ref. <https://github.com/julienXX/clj-slack>"
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.utils :as utils]
[clj-slack.core :as slack]
[clj-slack.chat :as slack.chat]))
@ -68,8 +69,8 @@
{:keys [channel-id]} post-opts
post-opts (dissoc post-opts :channel-id)
_ (when-not (string? token) (throw (ex-info "Expected `:conn-opts/token` string" (enc/typed-val token))))
_ (when-not (string? channel-id) (throw (ex-info "Expected `:post-opts/channel-id` string" (enc/typed-val channel-id))))
_ (when-not (string? token) (truss/ex-info! "Expected `:conn-opts/token` string" (truss/typed-val token)))
_ (when-not (string? channel-id) (truss/ex-info! "Expected `:post-opts/channel-id` string" (truss/typed-val channel-id)))
handler-fn
(fn a-handler:slack

View file

@ -1,7 +1,8 @@
(ns taoensso.telemere.sockets
"Basic TCP/UDP socket handlers."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.utils :as utils])
(:import
@ -90,8 +91,8 @@
socket (DatagramSocket.) ; No need to change socket once created
lock (Object.)]
(when-not (string? host) (throw (ex-info "Expected `:host` string" (enc/typed-val host))))
(when-not (int? port) (throw (ex-info "Expected `:port` int" (enc/typed-val port))))
(when-not (string? host) (truss/ex-info! "Expected `:host` string" (truss/typed-val host)))
(when-not (int? port) (truss/ex-info! "Expected `:port` int" (truss/typed-val port)))
(.connect socket (InetSocketAddress. (str host) (int port)))

View file

@ -1,7 +1,8 @@
(ns taoensso.telemere.streams
"Interop support for standard stream/s -> Telemere."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.encore :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.impl :as impl]))
(enc/defonce ^:private orig-*out* "Original `*out*` on ns load" *out*)

View file

@ -3,7 +3,8 @@
Intended to help ease migration from Timbre to Telemere."
(:require
[clojure.string :as str]
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.impl :as impl]
[taoensso.telemere :as tel]))
@ -21,10 +22,10 @@
(defn ^:no-doc parse-vargs
"Private, don't use. Adapted from Timbre."
[format-msg? vargs]
(let [[v0] vargs]
(let [[v0] vargs]
(if (enc/error? v0)
(let [error v0
(if (truss/error? v0)
(let [error v0
vargs (enc/vrest vargs)
pattern (if format-msg? (let [[v0] vargs] v0) nil)
vargs (if format-msg? (enc/vrest vargs) vargs)

View file

@ -8,7 +8,8 @@
`clojure.tools.logging` - For env config to match library's conventions."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.impl :as impl]
[clojure.tools.logging :as ctl]))

View file

@ -4,6 +4,7 @@
(:require
[clojure.string :as str]
#?(:clj [clojure.java.io :as jio])
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere.impl :as impl]))
@ -118,8 +119,9 @@
:hex/secure (hex-uid-fn {:secure? true, :root-len root-len, :child-len child-len})
nil)))
(enc/unexpected-arg! kind
{:context `uid-fn
(truss/unexpected-arg! kind
{:param 'kind
:context `uid-fn
:expected
'#{:uuid :uuid-str :default,
:nano/secure [:nano/secure <root-len> <child-len>]
@ -205,7 +207,7 @@
[{:keys [type msg data]} ...] cause chain."
[signal]
(enc/if-let [error (get signal :error)
chain (enc/ex-chain :as-map error)]
chain (truss/ex-chain :as-map error)]
(assoc signal :error chain)
(do signal)))
@ -224,9 +226,8 @@
(if (.canWrite file)
file
(throw
(ex-info "Unable to prepare writable `java.io.File`"
{:path (.getAbsolutePath file)}))))))
(truss/ex-info! "Unable to prepare writable `java.io.File`"
{:path (.getAbsolutePath file)})))))
#?(:clj
(defn ^:no-doc file-stream
@ -253,7 +254,7 @@
[{:keys [file append?]
:or {append? true}}]
(when-not file (throw (ex-info "Expected `:file` value" (enc/typed-val file))))
(when-not file (truss/ex-info! "Expected `:file` value" (truss/typed-val file)))
(let [file (writeable-file! file)
stream_ (volatile! (file-stream file append?))
@ -364,8 +365,8 @@
socket-fn default-socket-fn
ssl-socket-fn default-ssl-socket-fn}}]
(when-not (string? host) (throw (ex-info "Expected `:host` string" (enc/typed-val host))))
(when-not (int? port) (throw (ex-info "Expected `:port` int" (enc/typed-val port))))
(when-not (string? host) (truss/ex-info! "Expected `:host` string" (truss/typed-val host)))
(when-not (int? port) (truss/ex-info! "Expected `:port` int" (truss/typed-val port)))
(let [new-conn! ; => [<java.net.Socket> <java.io.OutputStream>], or throws
(fn []
@ -379,7 +380,7 @@
[socket (.getOutputStream socket)])
(catch Exception ex
(throw (ex-info "Failed to create connection" opts ex)))))
(truss/ex-info! "Failed to create connection" opts ex))))
conn_ (volatile! (new-conn!))
open?_ (enc/latom true)
@ -464,7 +465,7 @@
(s+nl " " class "/" method " at " file ":" line)))
(str sb))))
(comment (println (format-clj-stacktrace (:trace (enc/ex-map (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"})))))))
(comment (println (format-clj-stacktrace (:trace (truss/ex-map (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"})))))))
(defn format-error-fn
"Experimental, subject to change.
@ -477,7 +478,7 @@
nls enc/newlines]
(fn format-error [error]
(when-let [em (enc/ex-map error)]
(when-let [em (truss/ex-map error)]
(let [sb (enc/str-builder)
s+ (partial enc/sb-append sb)
{:keys [chain trace]} em]
@ -497,9 +498,9 @@
(str sb)))))))
(comment
(do (throw (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"}))))
(do (enc/ex-map (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"}))))
(println (str "--\n" ((format-error-fn) (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"}))))))
(do (throw (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"}))))
(do (truss/ex-map (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"}))))
(println (str "--\n" ((format-error-fn) (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"}))))))
;;;;
@ -680,8 +681,8 @@
(assoc!* m k v)
;; Main keys to include with modified val
:error (if-let [chain (enc/ex-chain :as-map v)] (assoc! m k chain) m) ; As `expand-signal-error`
:msg_ (assoc!* m k (force v)) ; As `force-signal-msg`
:error (if-let [chain (truss/ex-chain :as-map v)] (assoc! m k chain) m) ; As `expand-signal-error`
:msg_ (assoc!* m k (force v)) ; As `force-signal-msg`
;; Implementation keys to always exclude
(clojure.core/into ()
@ -748,15 +749,14 @@
:json
#?(:cljs pr-json
:clj
(throw
(ex-info "`:json` pr-fn only supported in Cljs. To output JSON in Clj, please provide an appropriate unary fn instead (e.g. jsonista/write-value-as-string)."
{})))
(truss/ex-info! "`:json` pr-fn only supported in Cljs. To output JSON in Clj, please provide an appropriate unary fn instead (e.g. jsonista/write-value-as-string)."
{}))
(if (fn? pr-fn)
(do pr-fn)
(enc/unexpected-arg! pr-fn
{:context `pr-signal-fn
:param 'pr-fn
(truss/unexpected-arg! pr-fn
{:param 'pr-fn
:context `pr-signal-fn
:expected
#?(:clj '#{:edn unary-fn}
:cljs '#{:edn :json unary-fn})}))))]
@ -813,5 +813,5 @@
{:my-k1 #{:a :b :c}
:msg "hi"
:data {:a :A}
;; :error (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"}))
;; :error (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"}))
:run (/ 1 0)}))))))

View file

@ -2,7 +2,8 @@
(:require
[clojure.test :as test :refer [deftest testing is]]
[clojure.core.async :as async]
[taoensso.encore :as enc :refer [throws? submap?] :rename {submap? sm?}]
[taoensso.truss :as truss :refer [throws? submap?] :rename {submap? sm?}]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere :as tel]
[taoensso.telemere.impl :as impl
@ -32,12 +33,12 @@
(do (def t2s "2024-02-02T02:02:02.120Z") (def t2 (enc/as-inst t2s)) (def udt2 (enc/as-udt t2)))
(do (def t3s "2024-03-03T03:03:03.130Z") (def t3 (enc/as-inst t3s)) (def udt3 (enc/as-udt t3)))
(def ex-info-type (#'enc/ex-type (ex-info "" {})))
(def ex1 (ex-info "Ex1" {}))
(def ex2 (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"})))
(def ex2-chain (enc/ex-chain :as-map ex2))
(def ex-info-type (truss/ex-type (truss/ex-info "" {})))
(def ex1 (truss/ex-info "Ex1" {}))
(def ex2 (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"})))
(def ex2-chain (truss/ex-chain :as-map ex2))
(defn ex1! [] (throw ex1))
(defn ex1? [x] (= (enc/ex-root x) ex1)))
(defn ex1? [x] (= (truss/ex-root x) ex1)))
(let [rt-sig-filter_ (atom nil)
sig-handlers_ (atom nil)]
@ -848,7 +849,7 @@
[(is (= sig*1 sig*2) "Default :pr-fn is :edn")
(is
(enc/submap? sig*1
(sm? sig*1
{:schema 1, :kind :event, :id ::ev-id, :level :info,
:ns "taoensso.telemere-tests"
:msg_ "a b"
@ -860,7 +861,7 @@
(testing ":json pr-fn"
(let [sig* (enc/read-json ((tel/pr-signal-fn {:pr-fn :json}) sig))]
(is
(enc/submap? sig*
(sm? sig*
{"schema" 1, "kind" "event", "id" "taoensso.telemere-tests/ev-id",
"level" "info", "ns" "taoensso.telemere-tests"
"msg_" "a b"

View file

@ -18,7 +18,8 @@
{:author "Peter Taoussanis (@ptaoussanis)"}
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.truss :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.impl :as impl])
(:import
@ -87,7 +88,7 @@
;; Vector of markers
(reduce
(fn [acc in] (into acc (marker-names in)))
#{} (have vector? marker-or-markers))))))
#{} (truss/have vector? marker-or-markers))))))
(comment
(let [m1 (est-marker! "M1")