Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to log which is the Pretty print like pprint by clojure.tools.logging?

I am using org.clojure/tools.logging. I want to get a function which can pretty print the log, but I can't find it. For example, the content which i want to print is

{:status 401,
 :headers {"Content-Type" "application/octet-stream"},
 :body {:error "You don't login."}}

but i call the function name is info,I get this

{:status 401, :headers {Content-Type application/octet-stream}, :body {:error You don't login.}}
like image 812
ipaomian Avatar asked Oct 19 '25 02:10

ipaomian


1 Answers

How about something like this:

(require '[clojure.pprint :as pprint])

(defn pformat [& args]
        (with-out-str
          (apply pprint/pprint args)))

Then:

(require '[clojure.tools.logging :as log])

(log/info (pformat {:status 401,
                    :headers {"Content-Type" "application/octet-stream"},
                    :body {:error "You don't login."}}))

Which outputs something like this:

Apr 29, 2015 9:43:40 AM user invoke
INFO: {:headers {"Content-Type" "application/octet-stream"},
 :status 401,
 :body {:error "You don't login."}}
like image 98
John Wiseman Avatar answered Oct 21 '25 17:10

John Wiseman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!