Liking cljdoc? Tell your friends :D

taoensso.telemere.utils

Misc utils useful for Telemere handlers, middleware, etc.

error-in-signal->mapsclj/s

(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.
source

error-signal?clj/s

(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.
source

file-writerclj

(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.
source

format-error-fnclj/s

(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
source

format-inst-fnclj/s≠

clj
(format-inst-fn)
(format-inst-fn {:keys [formatter zone]
                 :or {formatter java.time.format.DateTimeFormatter/ISO_INSTANT
                      zone java.time.ZoneOffset/UTC}})
cljs
(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".
source

format-nsecs-fnclj/s

(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.
source

format-signal->edn-fnclj/s

(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.
source

format-signal->json-fnclj/s≠

clj
(format-signal->json-fn)
(format-signal->json-fn {:keys [pr-json-fn prep-fn]
                         :or {prep-fn (comp error-in-signal->maps
                                            minify-signal)}})
cljs
(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.
source

format-signal->str-fnclj/s

(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.
source

format-signal-prelude-fnclj/s

(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"
source

host-ipclj

(host-ip)
(host-ip timeout-msecs timeout-val)
Returns cached local host IP address string, or `timeout-val` (default "UnknownHost").
source

hostnameclj

(hostname)
(hostname timeout-msecs timeout-val)
Returns cached local hostname string, or `timeout-val` (default "UnknownHost").
source

js-console-loggercljs

(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!
source

minify-signalclj/s

(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.
source

newlineclj/s

Single system newline
source

pr-ednclj/s

(pr-edn x)
Prints given arg to an edn string readable with `read-edn`.
source

pr-jsoncljs

(pr-json x)
Returns given Cljs argument as JSON string.
source

thread-idclj

(thread-id)
Returns long id of current thread.
source

thread-nameclj

(thread-name)
Returns string name of current thread.
source

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close