torsdag 17 juli 2014

Spy with Timbre

Peter Taoussanis Timbre logging library is awesome. It's dead easy to get started with - add a dependecy and you're done.

One really usable features in it (apart from the ordinary "write this to log" functions) is spy.

spy let's you wrap an expression and log both the expression and it's result, like so:

(require '[taoensso.timbre :as timbre])

(defn some-function [argh]
    (timbre/spy (reverse argh)))

(defn some-other-function [x]
    (timbre/spy (map rand-int x)))

(some-other-function (some-function [1 2 34]))
2014-Jul-17 18:12:06 +0200 Albatron-5 DEBUG [user] - (reverse argh) (34 2 1)
2014-Jul-17 18:12:06 +0200 Albatron-5 DEBUG [user] - (map rand-int x) (30 0 0)
-> (30 0 0)

The result of the two above functions are not apparent, and there is good reason to keep an eye on intermediate results. This can be tedious when not in light-table. Not so with spy.

Inga kommentarer:

Skicka en kommentar