taoensso.timbre
Simple, flexible logging for Clojure/Script. No XML.
*config*
dynamic
See `example-config` for info.
*context*
dynamic
General-purpose dynamic logging context. Context will be included in
appender data map at logging time.
-log!
(-log! config level ?ns-str ?file ?line msg-type ?err vargs_ ?base-data callsite-id)
Core low-level log fn. Implementation detail!
-log-and-rethrow-errors
macro
(-log-and-rethrow-errors ?line & body)
-log-errors
macro
(-log-errors ?line & body)
-logged-future
macro
(-logged-future ?line & body)
-spy
macro
(-spy ?line config level name expr)
-with-elision
macro
(-with-elision level-form ns-str-form & body)
Implementation detail.
Executes body iff given level and ns pass compile-time elision.
color-str
(color-str color & xs)
debugf
macro
(debugf & args)
default-output-fn
(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-timestamp-opts
Controls (:timestamp_ data)
errorf
macro
(errorf & args)
example-config
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 _}
: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
: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`)
:profile-stats ; From `profile` macro
**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!`.
fatalf
macro
(fatalf & args)
handle-uncaught-jvm-exceptions!
(handle-uncaught-jvm-exceptions! & [handler])
Sets JVM-global DefaultUncaughtExceptionHandler.
log
macro
(log level & args)
log!
macro
(log! level msg-type args & [opts])
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`.
log*
macro
(log* config level & args)
log-and-rethrow-errors
macro
(log-and-rethrow-errors & body)
log-env
macro
(log-env)
(log-env level)
(log-env level name)
(log-env config level name)
log-errors
macro
(log-errors & body)
log?
(log? level)
(log? level ?ns-str)
(log? level ?ns-str config)
Runtime 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
logf
macro
(logf level & args)
logf*
macro
(logf* config level & args)
logged-future
macro
(logged-future & body)
logging-enabled?
(logging-enabled? level compile-time-ns)
merge-config!
(merge-config! m)
println-appender
(println-appender & [{:keys [stream], :or {stream :auto}}])
Returns a simple `println` appender for Clojure/Script.
Use with ClojureScript requires that `cljs.core/*print-fn*` be set.
:stream (clj only) - e/o #{:auto :*out* :*err* :std-err :std-out <io-stream>}.
refer-timbre
(refer-timbre)
Shorthand for:
(require '[taoensso.timbre :as timbre
:refer (log trace debug info warn error fatal report
logf tracef debugf infof warnf errorf fatalf reportf
spy get-env log-env)])
(require '[taoensso.timbre.profiling :as profiling
:refer (pspy p defnp profile)])
report
macro
(report & args)
reportf
macro
(reportf & args)
set-config!
(set-config! m)
set-level!
(set-level! level)
sometimes
macro
(sometimes probability & body)
Handy for sampled logging, etc.
spit-appender
(spit-appender & [{:keys [fname], :or {fname "./timbre-spit.log"}}])
Returns a simple `spit` file appender for Clojure.
spy
macro
(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.
stacktrace
(stacktrace err)
(stacktrace err opts)
str-println
(str-println & xs)
swap-config!
(swap-config! f & args)
tracef
macro
(tracef & args)
with-config
macro
(with-config config & body)
with-context
macro
(with-context context & body)
with-default-outs
macro
(with-default-outs & body)
with-level
macro
(with-level level & body)
with-log-level
macro
(with-log-level level & body)
with-logging-config
macro
(with-logging-config config & body)
with-merged-config
macro
(with-merged-config config & body)