Skip to content
A tiny value-oriented debugging logger for Clojure(Script), powered by transducers
Clojure
Branch: master
Clone or download
athos Merge pull request #1 from athos/feature/instrument
Add instrumentation feature
Latest commit 0049af6 Oct 14, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Exclude postmortem.instrument.cljs from test coverage target nses Oct 11, 2019
example Update example code Oct 3, 2019
src/postmortem Add docstrings for instrument/unstrument Oct 14, 2019
test/postmortem
.gitignore Ignore .cpcache Nov 8, 2018
CHANGELOG.md first commit Nov 8, 2018
LICENSE first commit Nov 8, 2018
README.md Update lib description Oct 10, 2019
deps.edn Exclude postmortem.instrument.cljs from test coverage target nses Oct 11, 2019
project.clj Update lib description Oct 10, 2019

README.md

Postmortem

Clojars Project CircleCI codecov

A tiny value-oriented debugging logger for Clojure(Script), powered by transducers

Installation

Add the following to your project :dependencies:

Clojars Project

Usage

(require '[postmortem.core :as pm])

(defn fib [n]
  (loop [n n a 0 b 1]
    (pm/dump :fib)
    (if (= n 0)
      a
      (recur (dec n) b (+ a b)))))

(fib 5) ;=> 5
(pm/log-for :fib)
;=> [{:n 5, :a 0, :b 1}
;    {:n 4, :a 1, :b 1}
;    {:n 3, :a 1, :b 2}
;    {:n 2, :a 2, :b 3}
;    {:n 1, :a 3, :b 5}
;    {:n 0, :a 5, :b 8}]

(defn fib2 [n]
  (loop [n n a 0 b 1]
    (pm/dump :fib2 (filter #(even? (:n %))))
    (if (= n 0)
      a
      (recur (dec n) b (+ a b)))))

(fib2 5) ;=> 5
(pm/log-for :fib2)
;=> [{:n 4, :a 1, :b 1} {:n 2, :a 2, :b 3} {:n 0, :a 5, :b 8}]

(require '[postmortem.xforms :as xf])

(defn fib3 [n]
  (loop [n n a 0 b 1]
    (pm/dump :fib3
             (comp (map-indexed #(assoc %2 :id %1))
                   (xf/take-last 3)))
    (if (= n 0)
      a
      (recur (dec n) b (+ a b)))))

(fib3 5) ;=> 5
(pm/log-for :fib3)
;=> [{:n 2, :a 2, :b 3, :id 3} {:n 1, :a 3, :b 5, :id 4} {:n 0, :a 5, :b 8, :id 5}]

(pm/logs)
;=> {:fib [{:n 5, :a 0, :b 1}
;          {:n 4, :a 1, :b 1}
;          {:n 3, :a 1, :b 2}
;          {:n 2, :a 2, :b 3}
;          {:n 1, :a 3, :b 5}
;          {:n 0, :a 5, :b 8}]
;    :fib2 [{:n 4, :a 1, :b 1} {:n 2, :a 2, :b 3} {:n 0, :a 5, :b 8}]
;    :fib3 [{:n 2, :a 2, :b 3, :id 3} {:n 1, :a 3, :b 5, :id 4} {:n 0, :a 5, :b 8, :id 5}]}

(pm/reset!)
(pm/logs) ;=> {}

License

Copyright © 2018 Shogo Ohta

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

You can’t perform that action at this time.