Skip to content

Commit

Permalink
[nop] Housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Oct 30, 2024
1 parent f4ac146 commit 687363a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 89 deletions.
16 changes: 4 additions & 12 deletions projects/main/src/taoensso/telemere/impl.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -272,16 +272,8 @@
sigs/IFilterableSignal
(allow-signal? [_ sig-filter] (sig-filter kind ns id level))
(signal-value [_ handler-sample-rate]
(let [sig-val (force signal-value_)]
(or
(when handler-sample-rate
(when (map? sig-val)
;; Replace call sample rate with combined (call * handler) sample rate
(assoc sig-val :sample-rate
(*
(double handler-sample-rate)
(double (or (get sig-val :sample-rate) 1.0))))))
sig-val))))
(sigs/signal-with-combined-sample-rate handler-sample-rate
(force signal-value_))))

(defn wrap-signal
"Used by `taoensso.telemere/dispatch-signal!`."
Expand Down Expand Up @@ -645,8 +637,8 @@

middleware-form
(if-let [middleware+ (get opts :middleware+)]
`(taoensso.telemere/comp-middleware taoensso.telemere/*middleware* ~middleware+)
(get opts :middleware `taoensso.telemere/*middleware*))
`(taoensso.encore/comp-middleware taoensso.telemere/*middleware* ~middleware+)
(get opts :middleware `taoensso.telemere/*middleware*))

kvs-form
(not-empty
Expand Down
9 changes: 5 additions & 4 deletions projects/main/src/taoensso/telemere/postal.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"Email handler using `postal`,
Ref. <https://github.com/drewr/postal>."
(:require
[taoensso.encore :as enc :refer [have have?]]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere.utils :as utils]
[postal.core :as postal]))

Expand Down Expand Up @@ -32,9 +33,9 @@
sb (enc/str-builder)
s+spc (enc/sb-appender sb " ")]

(when level (s+spc (utils/format-level level)))
(when kind (s+spc (utils/upper-qn kind)))
(when id (s+spc (utils/format-id nil id)))
(when level (s+spc (sigs/format-level level)))
(when kind (s+spc (sigs/upper-qn kind)))
(when id (s+spc (sigs/format-id nil id)))
(when-let [msg (force msg_)] (s+spc "- " msg))

(enc/substr (str sb) 0 max-len))))))
Expand Down
71 changes: 9 additions & 62 deletions projects/main/src/taoensso/telemere/utils.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,18 @@
(:require
[clojure.string :as str]
#?(:clj [clojure.java.io :as jio])
[taoensso.encore :as enc :refer [have have?]]
[taoensso.encore :as enc]
[taoensso.encore.signals :as sigs]
[taoensso.telemere.impl :as impl]))

(comment
(require '[taoensso.telemere :as tel])
(remove-ns (symbol (str *ns*)))
(:api (enc/interns-overview)))

;;;; Private

(enc/def* ^:no-doc upper-qn
"Private, don't use.
`:foo/bar` -> \"FOO/BAR\", etc."
{:tag #?(:clj 'String :cljs 'string)}
(enc/fmemoize (fn [x] (str/upper-case (enc/as-qname x)))))

(comment (upper-qn :foo/bar))

(enc/def* ^:no-doc format-level
"Private, don't use.
`:info` -> \"INFO\",
`5` -> \"LEVEL:5\", etc."
{:tag #?(:clj 'String :cljs 'string)}
(enc/fmemoize
(fn [x]
(if (keyword? x)
(upper-qn x)
(str "LEVEL:" x)))))

(comment (format-level :info))

(enc/def* ^:no-doc format-id
"Private, don't use.
`:foo.bar/baz` -> \"::baz\", etc."
{:tag #?(:clj 'String :cljs 'string)}
(enc/fmemoize
(fn [ns x]
(if (keyword? x)
(if (= (namespace x) ns)
(str "::" (name x))
(str x))
(str x)))))

(comment
(format-id (str *ns*) ::id1)
(format-id nil ::id1))

(enc/def* ^:private format-location
"Private, don't use.
Returns \"<ns/file>(<line>,<column>)\", etc."
{:tag #?(:clj 'String :cljs 'string)}
(enc/fmemoize
(fn [ns line column file]
(when-let [base (or ns file)]
(if line
(if column
(str base "(" line "," column ")")
(str base "(" line ")"))
base)))))
;;;;

(comment
(format-location "my-ns" 120 8 nil)
(format-location nil 120 8 *file*))
;; (enc/defalias sigs/upper-qn sigs/format-level sigs/format-id sigs/format-location)

;;;; Unique IDs (UIDs)

Expand Down Expand Up @@ -573,9 +522,9 @@
s+spc (enc/sb-appender sb " ")]

(when inst (when-let [ff format-inst-fn] (s+spc (ff inst))))
(when level (s+spc (format-level level)))
(when level (s+spc (sigs/format-level level)))

(if kind (s+spc (upper-qn kind)) (s+spc "DEFAULT"))
(if kind (s+spc (sigs/upper-qn kind)) (s+spc "DEFAULT"))
#?(:clj (s+spc (hostname)))

;; As `format-location`
Expand All @@ -587,16 +536,14 @@
(when-let [c (get signal :column)] (s+ "," c))
(s+ ")"))))

(when id (s+spc (format-id ns id)))
(when id (s+spc (sigs/format-id ns id)))
(when-let [msg (force msg_)] (s+spc "- " msg))

(when-not (zero? (enc/sb-length sb))
(str sb))))))

(comment ((signal-preamble-fn) (tel/with-signal (tel/event! ::ev-id))))

(defn- not-empty-coll [x] (when x (if (coll? x) (not-empty x) x)))

(defn signal-content-fn
"Experimental, subject to change.
Returns a (fn content [signal]) that:
Expand Down Expand Up @@ -644,9 +591,9 @@
(when (and parent root) (af " root: " (vf (dissoc root :inst)))) ; {:keys [id uid]}
#?(:clj (when (and host incl-host?) (af " host: " (vf host)))) ; {:keys [ name ip]}
#?(:clj (when (and thread incl-thread?) (af " thread: " (vf thread)))) ; {:keys [group name id]}
(when (not-empty-coll data) (af " data: " (vf data)))
(when (enc/not-empty-coll data) (af " data: " (vf data)))
(when (and kvs incl-kvs?) (af " kvs: " (vf kvs)))
(when (not-empty-coll ctx) (af " ctx: " (vf ctx))))
(when (enc/not-empty-coll ctx) (af " ctx: " (vf ctx))))

(let [{:keys [run-form error]} signal]
(when run-form
Expand Down
12 changes: 1 addition & 11 deletions projects/main/test/taoensso/telemere_tests.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -781,17 +781,7 @@
;;;; Utils

(deftest _utils
[(testing "Basic utils"
[(is (= (utils/upper-qn :foo/bar) "FOO/BAR"))

(is (= (utils/format-level :info) "INFO"))
(is (= (utils/format-level 8) "LEVEL:8"))

(is (= (utils/format-id "foo.bar" :foo.bar/qux) "::qux"))
(is (= (utils/format-id "foo.baz" :foo.bar/qux) ":foo.bar/qux"))
(is (= (utils/format-id nil :foo.bar/qux) ":foo.bar/qux"))])

(testing "error-signal?"
[(testing "error-signal?"
[(is (= (utils/error-signal? {:error nil}) false))
(is (= (utils/error-signal? {:error ex1}) true))
(is (= (utils/error-signal? {:kind :error}) true))
Expand Down

0 comments on commit 687363a

Please sign in to comment.