Skip to content
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

How to pretty print with Timbre #184

Closed
theronic opened this issue Jul 21, 2016 · 5 comments
Closed

How to pretty print with Timbre #184

theronic opened this issue Jul 21, 2016 · 5 comments

Comments

@theronic
Copy link

Can I get Timbre to always pretty-print Clojure data structures, without modifying all my logging calls to Timbre?

@ptaoussanis
Copy link
Member

Hi Petrus, should be doable; would recommend looking into Timbre's middleware support.

Cheers!

@theronic
Copy link
Author

I never managed to get this going. Anyone have a middleware sample with pretty-printing Timbre?

@MrEbbinghaus
Copy link

MrEbbinghaus commented Jun 14, 2018

@theronic
I use following as middleware.

(fn [data] 
  (update data :vargs (partial mapv #(if (string? %) 
                                         % 
                                         (with-out-str (pprint %))))))]

The if string? is there, because pprint would print strings with \".

You could use condp for some advanced formating

(fn [x] 
 (condp #(%1 %2) x
  string? (clojure.string/upper-case x)
  neg? (str "minus " (* -1 x))
  (with-out-str (pprint x))

@ghost
Copy link

ghost commented Nov 30, 2018

Maybe include this example in the readme?

@MrEbbinghaus
Copy link

@urzds In this case it could be added as a middleware in the repo itself.

@ptaoussanis What do you think about this?

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

No branches or pull requests

3 participants