We can emit a log statement using Timbre's log
function, which accepts—at a minimum—the log level and a message to emit. The following code shows an example of an log
function.
(require '[taoensso.timbre :as timbre]) (timbre/log :info "This is an info message.") >> 2014-Nov-24 14:35:24 -0500 computer.local INFO [hipstr.handler] - This is an info message.
Alternatively, Timbre makes available a function for each logging level, thus relieving us from having to specify the log level with each call, as shown in the following code:
(timbre/info "This is an info message.")
Timbre's log
functions are similar to Clojure's str
and println
functions, as we can pass multiple strings to produce a single long string:
(timbre/info "This" "is" "an" "info" "message.")
No logging framework would be complete without the ability to log exceptions. Here is an example of appending an Exception:
(timbre/error (Exception. "Aw snap!") "Something bad happened." "It's really awful.")
Appenders will only emit messages that are emitted at a log level equal or higher to their minimum log level. As such, the following will not actually emit anything.
(timbre/set-level! :warn) (timbre/debug "You will never see this.")
As :debug
is a lower log level than :warn
, the preceding debug message will not be emitted.
3.144.123.155