Misc utils useful for Telemere handlers, middleware, etc.
(error-in-signal->maps signal)
Experimental, subject to change. Returns given signal with possible `:error` replaced by [{:keys [type msg data]} ...] cause chain. Useful when serializing signals to edn/JSON/etc.
(error-signal? signal)
Experimental, subject to change. Returns true iff given signal has an `:error` value, or a `:kind` or `:level` that indicates that it's an error.
(file-writer file append?)
Experimental, subject to change!! Opens the specified file and returns a stateful fn of 2 arities: [content] => Writes given content to file, or no-ops if closed. [] => Closes the writer. Thread safe. Automatically creates file and parent dirs as necessary. Writers MUST ALWAYS be manually closed after use! Useful for handlers that write to files, etc.
(format-error-fn)
(format-error-fn {:as _opts})
Experimental, subject to change. Returns a (fn format [error]) that: - Takes a platform error (`Throwable` or `js/Error`). - Returns a formatted human-readable string
(format-inst-fn)
(format-inst-fn {:keys [formatter zone]
:or {formatter java.time.format.DateTimeFormatter/ISO_INSTANT
zone java.time.ZoneOffset/UTC}})
(format-inst-fn)
(format-inst-fn {:keys [formatter]})
Experimental, subject to change without notice. Returns a (fn format [instant]) that: - Takes a platform instant (`java.time.Instant` or `js/Date`). - Returns a formatted human-readable string. Options: `:zone` (Clj only) `java.time.ZoneOffset` (defaults to UTC). `:formatter` `java.time.format.DateTimeFormatter` (Clj) or `goog.i18n.DateTimeFormat` (Cljs), Defaults to `ISO8601` formatter (`YYYY-MM-DDTHH:mm:ss.sssZ`), e.g.: "2011-12-03T10:15:130Z".
(format-nsecs-fn)
(format-nsecs-fn {:as _opts})
Experimental, subject to change. Returns a (fn format [nanosecs]) that: - Takes a long nanoseconds (e.g. runtime). - Returns a formatted human-readable string like: "1.00m", "4.20s", "340ms", "822μs", etc.
(format-signal->edn-fn)
(format-signal->edn-fn
{:keys [pr-edn-fn prep-fn]
:or {pr-edn-fn pr-edn prep-fn (comp error-in-signal->maps minify-signal)}})
Experimental, subject to change. Returns a (fn format->edn [signal]) that: - Takes a Telemere signal. - Returns edn string of the (minified) signal.
(format-signal->json-fn)
(format-signal->json-fn {:keys [pr-json-fn prep-fn]
:or {prep-fn (comp error-in-signal->maps
minify-signal)}})
(format-signal->json-fn)
(format-signal->json-fn
{:keys [pr-json-fn prep-fn]
:or {pr-json-fn pr-json prep-fn (comp error-in-signal->maps minify-signal)}})
Experimental, subject to change. Returns a (fn format->json [signal]) that: - Takes a Telemere signal. - Returns JSON string of the (minified) signal. (Clj only): An appropriate `:pr-json-fn` MUST be provided.
(format-signal->str-fn)
(format-signal->str-fn {:keys [format-signal-prelude-fn format-nsecs-fn
format-error-fn]
:or {format-signal-prelude-fn (format-signal-prelude-fn)
format-nsecs-fn (format-nsecs-fn)
format-error-fn (format-error-fn)}})
Experimental, subject to change. Returns a (fn format->str [signal]) that: - Takes a Telemere signal. - Returns a formatted string intended for text consoles, etc.
(format-signal-prelude-fn)
(format-signal-prelude-fn {:keys [format-inst-fn]
:or {format-inst-fn (format-inst-fn)}})
Experimental, subject to change. Returns a (fn format [signal]) that: - Takes a Telemere signal. - Returns a formatted prelude string like: "2024-03-26T11:14:51.806Z INFO EVENT Hostname taoensso.telemere(2,21) ::ev-id - msg"
(host-ip)
(host-ip timeout-msecs timeout-val)
Returns cached local host IP address string, or `timeout-val` (default "UnknownHost").
(hostname)
(hostname timeout-msecs timeout-val)
Returns cached local hostname string, or `timeout-val` (default "UnknownHost").
(js-console-logger level)
Returns JavaScript console logger to match given signal level: `:trace` -> `js/console.trace`, `:error` -> `js/console.error`, etc. Defaults to `js.console.log` for unmatched signal levels. NB: assumes that `js/console` exists, handler constructors should check first!
(minify-signal signal)
Experimental, subject to change. Returns minimal signal map, removing: - Keys with nil values, and - Keys with redundant values (`:extra-kvs`, `:location`, `:file`). Useful when serializing signals to edn/JSON/etc.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close