3

我正在使用org.clojure/tools.logging. 我想获得一个可以漂亮地打印日志的功能,但我找不到它。例如,我要打印的内容是

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

但我称函数名是info,我明白了

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

1 回答 1

4

像这样的东西怎么样:

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

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

然后:

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

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

输出如下:

Apr 29, 2015 9:43:40 AM user invoke
INFO: {:headers {"Content-Type" "application/octet-stream"},
 :status 401,
 :body {:error "You don't login."}}
于 2015-04-29T16:46:49.937 回答