A minimal, modern logging facade for Clojure/Script. Supports both traditional and structured logging.
The value of this var determines the Trove backend,
i.e. what happens on `trove/log!` calls.
When `nil`, all `trove/log!` calls will noop.
Otherwise value should be a (fn [ns coords level id lazy_]) with:
`ns` ------- String namespace of `log!` callsite, e.g. "my-app.utils"
`coords` --- ?[line column] of `log!` callsite, may be lost (nil) for macros wrapping `log!`
`level` ---- Keyword `:level` from `log!` call ∈ #{:trace :debug :info :warn :error :fatal :report}
`id` ------- ?Keyword `:id` from `log!` call, e.g. `:auth/login`, `::order-complete`, etc.
`lazy_` ---- {:keys [msg data error kvs]}, MAY be wrapped with `delay` so access with `force`:
`:msg` --- ?String `:msg` from `log!` call
`:data` -- ?Map `:data` from `log!` call, e.g. {:user-id 1234}
`:error` - ?Error `:error` from `log!` call, (`java.lang.Throwable`, `js/Error`, or nil)
`:kvs` --- ?Map of any other kvs from `log!` call, handy for custom `log-fn` opts, etc.
The configured `log-fn` may filter (conditionally noop), or produce the
relevant logging side effects (printing, etc.).
The configured `log-fn` will be called SYNCHRONOUSLY so:
- It has access to the `trove/log!` calling thread/context (can be handy).
- It should implement appropriate async/threading/backpressure for
expensive work.
Config:
Change dynamic value with `binding`.
Change root value with `set-log-fn!`.
Basic fns are provided for some common backends, see `taoensso.trove.x/get-log-fn`
with x ∈ #{console telemere timbre mulog tools-logging slf4j} (default console).(log! {:keys [level id msg data error]})Logs the given info to the currently configured backend (see `*log-fn*`)
and returns nil.
Common options:
`:level` -- ∈ #{:trace :debug :info :warn :error :fatal :report} (default `:info`)
`:id` ----- Optional keyword used to identify event, e.g. `:auth/login`, `::order-complete`, etc.
`:msg` ---- Optional message string describing event (use `str`, `format`, etc. as needed)
`:data` --- Optional arb map of structured data associated with event, e.g. {:user-id 1234}
`:error` -- Optional platform error (`java.lang.Throwable`, `js/Error`)
Advanced options:
`:ns` ----- Custom namespace string to override default
`:coords` - Custom [line column] to override default
`:let` ---- Bindings shared by lazy args: {:keys [msg data error kvs]}
<kvs> ----- Any other kvs will also be provided to `log-fn`, handy for
custom `log-fn` opts, etc.
Traditional logs typically include at least {:keys [level msg ...]}.
Structured logs typically include at least {:keys [level id data ...]}.(set-log-fn! f)Sets the root value of `*log-fn*` (see its docstring for more info).
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |