我是Clojure的新手,想了解在Clojure中记录日志的方法,我的编程背景是命令式的。在Java生产程序中,我通常会在方法的开始和结束处进行日志记录(调试/信息),类似于这样:
public void foo(){
logger.debug("starting method to embrace %s", rightIdioms);
doSomething();
logger.debug("successfully embraced %s idioms", idioms.length);
}
我熟悉记录日志的优缺点,并知道Clojure中可用的工具,
我还可以找到上述方法中记录日志的一些缺点,这加深了我在非命令式记录日志时感到的紧张情绪。
- logging is a side effect and clojure pushes to no-side-effects.
more lines-of-code or 'code-complexity': in java - having big classes is common (getters, setters, constructors), in clojure, expressions return values, logging 'difficults' the process and hardens small functions and namespaces: (one example would be the need to change from if to if-let or if-do to perform a logging):
(defn foo [x] (if (neg? x) (inc x) x)) (defn foo [x] (if (neg? x) (let [new-x (inc x)] (logger/debug (format "inc value, now %s" new-x) new-x)) x))
clojure/tap
或 tracing
进行日志记录,但不确定其是否完全有用。在Clojure中进行日志记录的方法或惯用方式是什么?