I'm new to clojure and would like to understand the approaches of logging in a clojure, coming from an imperative background. In a java production-program I would usually LOG (debug/info) in start-end of a method, something like that:
public void foo(){
logger.debug("starting method to embrace %s", rightIdioms);
doSomething();
logger.debug("successfully embraced %s idioms", idioms.length);
}
I'm familiar with the pro's/con's of logging and know the tools available for that in clojure,
I can also find some con's of logging in the approach mentioned above, which deepens the tension I feel when logging in none-imperative:
- 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))
I have read logging with clojure/tap
or tracing
but not sure i fully found it useful.
What are the approaches or the idiomatic way to do logging in clojure?