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 {:keys [file append?] :or {append? true}})
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.

Useful for basic handlers that write to a file, etc.

Notes:
  - Automatically creates file and parent dirs as necessary.
  - Writer should be manually closed after use (with zero-arity call).
  - Flushes after every write.
  - Thread safe, locks on single file stream.
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 human-readable error 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 instant 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 human-readable string like:
    "1.00m", "4.20s", "340ms", "822μs", etc.
source

format-signal-fnclj/s

(format-signal-fn)
(format-signal-fn {:keys [incl-newline? preamble-fn content-fn]
                   :or {incl-newline? true
                        preamble-fn (signal-preamble-fn)
                        content-fn (signal-content-fn)}})
Experimental, subject to change.
Returns a (fn format [signal]) that:
  - Takes a Telemere signal (map).
  - Returns a human-readable signal string.

Options:
  `:incl-newline?` - Include terminating system newline? (default true)
  `:preamble-fn`   - (fn [signal]) => signal preamble string.
  `:content-fn`    - (fn [signal]) => signal content  string.

See also `pr-signal-fn` for machine-readable output.
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, removing:
  - Keys with nil values, and
  - Keys with redundant values (`: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

pr-signal-fnclj/s

(pr-signal-fn pr-fn)
(pr-signal-fn pr-fn
              {:keys [incl-thread? incl-kvs? incl-newline? prep-fn]
               :or {incl-newline? true
                    prep-fn (comp error-in-signal->maps minify-signal)}})
Experimental, subject to change.
Returns a (fn pr [signal]) that:
  - Takes a Telemere signal (map).
  - Returns a machine-readable (minified) signal string.

Options:
  `pr-fn`          - ∈ #{<unary-fn> :edn :json (Cljs only)}
  `:incl-thread?`  - Include signal `:thread` info?      (default false)
  `:incl-kvs?`     - Include signal `:kvs`    info?      (default false)
  `:incl-newline?` - Include terminating system newline? (default true)

Examples:
  (pr-signal-fn :edn  {<opts>})
  (pr-signal-fn :json {<opts>}) ; Cljs only

  ;; To output JSON for Clj, you must provide an appropriate `pr-fn`.
  ;; `jsonista` is a good option, Ref. <https://github.com/metosin/jsonista>:
    (require '[jsonista.core :as jsonista])
    (pr-signal-fn jsonista/write-value-as-string {<opts>})

See also `format-signal-fn` for human-readable output.
source

remove-kvsclj/s

(remove-kvs signal)
Returns given signal without user-level kvs.
source

signal-content-fnclj/s

(signal-content-fn)
(signal-content-fn
  {:keys [incl-thread? incl-kvs? raw-error? format-nsecs-fn format-error-fn]
   :or {format-nsecs-fn (format-nsecs-fn) format-error-fn (format-error-fn)}})
Experimental, subject to change.
Returns a (fn content [signal]) that:
  - Takes a Telemere signal (map).
  - Returns a signal content ?string (incl. data, ctx, etc.).

Options:
  `:incl-thread?`    - Include signal `:thread` info? (default false)
  `:incl-kvs?`       - Include signal `:kvs`    info? (default false)
  `:raw-error?`      - Retain unformatted error?      (default false)
  `:format-nsecs-fn` - (fn [nanosecs]) => string.
  `:format-error-fn` - (fn [error])    => string.
source

signal-preamble-fnclj/s

(signal-preamble-fn)
(signal-preamble-fn {:keys [format-inst-fn]
                     :or {format-inst-fn (format-inst-fn)}})
Experimental, subject to change.
Returns a (fn preamble [signal]) that:
  - Takes a Telemere signal (map).
  - Returns a signal preamble ?string like:
    "2024-03-26T11:14:51.806Z INFO EVENT Hostname taoensso.telemere(2,21) ::ev-id - msg"

Options:
  `:format-inst-fn` - (fn format [instant]) => string.
source

tcp-socket-writerclj

(tcp-socket-writer {:keys [host port ssl? connect-timeout-msecs socket-fn
                           ssl-socket-fn]
                    :as opts
                    :or {connect-timeout-msecs 3000
                         socket-fn default-socket-fn
                         ssl-socket-fn default-ssl-socket-fn}})
Experimental, subject to change.
Connects to specified TCP socket and returns a stateful fn of 2 arities:
  [content] => Writes given content to socket, or no-ops if closed.
  []        => Closes the writer.

Useful for basic handlers that write to a TCP socket, etc.

Options:
  `:ssl?`                  - Use SSL/TLS?
  `:connect-timeout-msecs` - Connection timeout (default 3000 msecs)
  `:socket-fn`             - (fn [host port timeout]) => `java.net.Socket`
  `:ssl-socket-fn`         - (fn [socket host port])  => `java.net.Socket`

Notes:
  - Writer should be manually closed after use (with zero-arity call).
  - Flushes after every write.
  - Will retry failed writes once, then drop.
  - Thread safe, locks on single socket stream.
  - Advanced users may want a custom implementation using a connection
    pool and/or more sophisticated retry semantics, etc.
source

thread-idclj

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

thread-infoclj

(thread-info)
Returns {:keys [group name id]} for 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