Simple, flexible logging for Clojure/Script. No XML.
Simple, flexible logging for Clojure/Script. No XML.
General-purpose dynamic logging context
General-purpose dynamic logging context
(-log! config level ?ns-str ?file ?line msg-type ?err vargs_ ?base-data)
(-log! config
level
?ns-str
?file
?line
msg-type
?err
vargs_
?base-data
callsite-id)
Core low-level log fn. Implementation detail!
Core low-level log fn. Implementation detail!
(default-output-fn data)
(default-output-fn opts data)
Default (fn [data]) -> string output fn.
Use(partial default-output-fn <opts-map>)
to modify default opts.
Default (fn [data]) -> string output fn. Use`(partial default-output-fn <opts-map>)` to modify default opts.
Example (+default) Timbre v4 config map.
APPENDERS An appender is a map with keys: :min-level ; Level keyword, or nil (=> no minimum level) :enabled? ; :async? ; Dispatch using agent? Useful for slow appenders (clj only) :rate-limit ; [[ncalls-limit window-ms] <...>], or nil :output-fn ; Optional override for inherited (fn [data]) -> string :timestamp-opts ; Optional override for inherited {:pattern _ :locale _ :timezone _} (clj only) :ns-whitelist ; Optional, stacks with active config's whitelist :ns-blacklist ; Optional, stacks with active config's blacklist :fn ; (fn [data]) -> side effects, with keys described below
An appender's fn takes a single data map with keys:
:config ; Entire config map (this map, etc.)
:appender-id ; Id of appender currently dispatching
:appender ; Entire map of appender currently dispatching
:instant ; Platform date (java.util.Date or js/Date)
:level ; Keyword
:error-level? ; Is level e/o #{:error :fatal}?
:?ns-str ; String, or nil
:?file ; String, or nil
:?line ; Integer, or nil ; Waiting on CLJ-865
:?err ; First-arg platform error, or nil
:vargs ; Vector of raw args
:output_ ; Forceable - final formatted output string created
; by calling (output-fn <this-data-map>)
:msg_ ; Forceable - args as a string
:timestamp_ ; Forceable - string (clj only)
:hostname_ ; Forceable - string (clj only)
:output-fn ; (fn [data]) -> formatted output string
; (see default-output-fn
for details)
:context ; context value at log time (see with-context
)
**NB** - any keys not specifically documented here should be
considered private / subject to change without notice.
MIDDLEWARE Middleware are simple (fn [data]) -> ?data fns (applied left->right) that transform the data map dispatched to appender fns. If any middleware returns nil, NO dispatch will occur (i.e. the event will be filtered).
The example-config
source code contains further settings and details.
See also set-config!
, merge-config!
, set-level!
.
Example (+default) Timbre v4 config map. APPENDERS An appender is a map with keys: :min-level ; Level keyword, or nil (=> no minimum level) :enabled? ; :async? ; Dispatch using agent? Useful for slow appenders (clj only) :rate-limit ; [[ncalls-limit window-ms] <...>], or nil :output-fn ; Optional override for inherited (fn [data]) -> string :timestamp-opts ; Optional override for inherited {:pattern _ :locale _ :timezone _} (clj only) :ns-whitelist ; Optional, stacks with active config's whitelist :ns-blacklist ; Optional, stacks with active config's blacklist :fn ; (fn [data]) -> side effects, with keys described below An appender's fn takes a single data map with keys: :config ; Entire config map (this map, etc.) :appender-id ; Id of appender currently dispatching :appender ; Entire map of appender currently dispatching :instant ; Platform date (java.util.Date or js/Date) :level ; Keyword :error-level? ; Is level e/o #{:error :fatal}? :?ns-str ; String, or nil :?file ; String, or nil :?line ; Integer, or nil ; Waiting on CLJ-865 :?err ; First-arg platform error, or nil :vargs ; Vector of raw args :output_ ; Forceable - final formatted output string created ; by calling (output-fn <this-data-map>) :msg_ ; Forceable - args as a string :timestamp_ ; Forceable - string (clj only) :hostname_ ; Forceable - string (clj only) :output-fn ; (fn [data]) -> formatted output string ; (see `default-output-fn` for details) :context ; *context* value at log time (see `with-context`) **NB** - any keys not specifically documented here should be considered private / subject to change without notice. MIDDLEWARE Middleware are simple (fn [data]) -> ?data fns (applied left->right) that transform the data map dispatched to appender fns. If any middleware returns nil, NO dispatch will occur (i.e. the event will be filtered). The `example-config` source code contains further settings and details. See also `set-config!`, `merge-config!`, `set-level!`.
(log! level msg-type args & [opts])
Core low-level log macro. Useful for tooling, etc.
level
- must eval to a valid logging levelmsg-type
- must eval to e/o #{:p :f nil}opts
- ks e/o #{:config :?err :?ns-str :?file :?line :?base-data}Supports compile-time elision when compile-time const vals
provided for level
and/or ?ns-str
.
Core low-level log macro. Useful for tooling, etc. * `level` - must eval to a valid logging level * `msg-type` - must eval to e/o #{:p :f nil} * `opts` - ks e/o #{:config :?err :?ns-str :?file :?line :?base-data} Supports compile-time elision when compile-time const vals provided for `level` and/or `?ns-str`.
(may-log? level)
(may-log? level ?ns-str)
(may-log? level ?ns-str ?config)
Runtime check: would Timbre currently log at the given logging level?
?ns-str
arg required to support ns filteringconfig
arg required to support non-global configRuntime check: would Timbre currently log at the given logging level? * `?ns-str` arg required to support ns filtering * `config` arg required to support non-global config
(sometimes probability & body)
Handy for sampled logging, etc.
Handy for sampled logging, etc.
(spy expr)
(spy level expr)
(spy level name expr)
(spy config level name expr)
Evaluates named expression and logs its result. Always returns the result. Defaults to :debug logging level and unevaluated expression as name.
Evaluates named expression and logs its result. Always returns the result. Defaults to :debug logging level and unevaluated expression as name.
(with-context context & body)
Executes body so that given arbitrary data will be included in the data map passed to appenders for any enclosed logging calls.
(with-context {:user-name "Stu"} ; Will be incl. in data dispatched to appenders (info "User request"))
Executes body so that given arbitrary data will be included in the data map passed to appenders for any enclosed logging calls. (with-context {:user-name "Stu"} ; Will be incl. in data dispatched to appenders (info "User request"))
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close