8000 Simple logger implemented around one-shot session by athos · Pull Request #11 · athos/Postmortem · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Simple logger implemented around one-shot session #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 29, 2021

Conversation

athos
Copy link
Owner
@athos athos commented Mar 22, 2021

This PR explores how useful a simple logger is, such as:

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

(def f (pm/make-logger (filter even?)))

(map f (range 10))
(f) ;=> [0 2 4 6 8]

This looks much simpler than the code with existing APIs:

(def sess (pm/make-session (filter even?)))

(map #(pm/spy>> sess :key identity %) (range 10))
(pm/log-for sess :key)

A simple logger is implemented with a one-shot session, and the user doesn't have to reset it every time after peeking the log. This nature would be especially useful when you repeat the cycle of "debug, modify, (re-)eval".

@codecov
Copy link
codecov bot commented Mar 22, 2021

Codecov Report

Merging #11 (07d723b) into master (4b31ad1) will increase coverage by 1.11%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##
8000
           master      #11      +/-   ##
==========================================
+ Coverage   91.31%   92.43%   +1.11%     
==========================================
  Files           7        7              
  Lines         357      370      +13     
  Branches       18       17       -1     
==========================================
+ Hits          326      342      +16     
+ Misses         13       11       -2     
+ Partials       18       17       -1     
Impacted Files Coverage Δ
src/postmortem/core.cljc 85.32% <100.00%> (+1.98%) ⬆️
src/postmortem/session.cljc 97.59% <0.00%> (+3.61%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4b31ad1...07d723b. Read the comment docs.

@athos athos changed the title Add simple logger implemented around one-shot session Simple logger implemented around one-shot session Mar 22, 2021
@athos athos force-pushed the feature/simple-logger branch 2 times, most recently from f579a55 to 4787826 Compare March 24, 2021 14:33
@athos
Copy link
Owner Author
athos commented Mar 24, 2021

I found this simple logger quite useful to insert a debug log to each step of threading macros:

(def f (pm/make-logger))

(->> (range 10)
     f
     (filter even?)
     f
     (map #(* % %))
     f
     (apply +))

In comparison with:

(->> (range 10)
     (pm/spy>> :log)
     (filter even?)
     (pm/spy>> :log)
     (map #(* % %))
     (pm/spy>> :log)
     (apply +))

@athos athos force-pushed the feature/simple-logger branch from 4787826 to 94ffd28 Compare March 25, 2021 12:39
@athos athos marked this pull request as ready for review March 26, 2021 00:29
@athos athos force-pushed the feature/simple-logger branch from 94ffd28 to 0247eb9 Compare March 27, 2021 14:50
@athos
Copy link
Owner Author
athos commented Mar 27, 2021

I'm wondering if a variant of the simple logger could also be useful, such like:

(def f (pm/make-multi-logger))

(loop [n 5 sum 0]
  (if (= n 0)
    sum
    (recur (f :n (dec n)) (f :sum (+ sum n)))))

(f) ;=> {:n [4 3 2 1 0] :sum [5 9 12 14 15]}

@athos athos force-pushed the feature/simple-logger branch from 0247eb9 8013 to 273c2e3 Compare March 27, 2021 15:14
@athos athos merged commit c230064 into master Mar 29, 2021
@athos athos deleted the feature/simple-logger branch March 29, 2021 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0