[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"} :scm {:name "git" :url "https://github.com/taoensso/telemere"}
:dependencies :dependencies
[[com.taoensso/encore "3.132.0"]] [[com.taoensso/truss "2.0.0-SNAPSHOT"]
[com.taoensso/encore "3.132.0"]]
:test-paths ["test" #_"src"] :test-paths ["test" #_"src"]

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,7 +1,8 @@
(ns taoensso.telemere.streams (ns taoensso.telemere.streams
"Interop support for standard stream/s -> Telemere." "Interop support for standard stream/s -> Telemere."
(:require (:require
[taoensso.encore :as enc :refer [have have?]] [taoensso.encore :as truss]
[taoensso.encore :as enc]
[taoensso.telemere.impl :as impl])) [taoensso.telemere.impl :as impl]))
(enc/defonce ^:private orig-*out* "Original `*out*` on ns load" *out*) (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." Intended to help ease migration from Timbre to Telemere."
(:require (:require
[clojure.string :as str] [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.impl :as impl]
[taoensso.telemere :as tel])) [taoensso.telemere :as tel]))
@ -23,7 +24,7 @@
[format-msg? vargs] [format-msg? vargs]
(let [[v0] vargs] (let [[v0] vargs]
(if (enc/error? v0) (if (truss/error? v0)
(let [error v0 (let [error v0
vargs (enc/vrest vargs) vargs (enc/vrest vargs)
pattern (if format-msg? (let [[v0] vargs] v0) nil) pattern (if format-msg? (let [[v0] vargs] v0) nil)

View file

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

View file

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

View file

@ -2,7 +2,8 @@
(:require (:require
[clojure.test :as test :refer [deftest testing is]] [clojure.test :as test :refer [deftest testing is]]
[clojure.core.async :as async] [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.encore.signals :as sigs]
[taoensso.telemere :as tel] [taoensso.telemere :as tel]
[taoensso.telemere.impl :as impl [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 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))) (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 ex-info-type (truss/ex-type (truss/ex-info "" {})))
(def ex1 (ex-info "Ex1" {})) (def ex1 (truss/ex-info "Ex1" {}))
(def ex2 (ex-info "Ex2" {:k2 "v2"} (ex-info "Ex1" {:k1 "v1"}))) (def ex2 (truss/ex-info "Ex2" {:k2 "v2"} (truss/ex-info "Ex1" {:k1 "v1"})))
(def ex2-chain (enc/ex-chain :as-map ex2)) (def ex2-chain (truss/ex-chain :as-map ex2))
(defn ex1! [] (throw ex1)) (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) (let [rt-sig-filter_ (atom nil)
sig-handlers_ (atom nil)] sig-handlers_ (atom nil)]
@ -848,7 +849,7 @@
[(is (= sig*1 sig*2) "Default :pr-fn is :edn") [(is (= sig*1 sig*2) "Default :pr-fn is :edn")
(is (is
(enc/submap? sig*1 (sm? sig*1
{:schema 1, :kind :event, :id ::ev-id, :level :info, {:schema 1, :kind :event, :id ::ev-id, :level :info,
:ns "taoensso.telemere-tests" :ns "taoensso.telemere-tests"
:msg_ "a b" :msg_ "a b"
@ -860,7 +861,7 @@
(testing ":json pr-fn" (testing ":json pr-fn"
(let [sig* (enc/read-json ((tel/pr-signal-fn {:pr-fn :json}) sig))] (let [sig* (enc/read-json ((tel/pr-signal-fn {:pr-fn :json}) sig))]
(is (is
(enc/submap? sig* (sm? sig*
{"schema" 1, "kind" "event", "id" "taoensso.telemere-tests/ev-id", {"schema" 1, "kind" "event", "id" "taoensso.telemere-tests/ev-id",
"level" "info", "ns" "taoensso.telemere-tests" "level" "info", "ns" "taoensso.telemere-tests"
"msg_" "a b" "msg_" "a b"

View file

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