Logging in Clojure

后端 未结 4 1121
北海茫月
北海茫月 2021-02-01 05:00

For Java development, I use Slf4j and Logback.

Logger logger = LoggerFactory.getLogger(HelloWorld.class);
logger.debug(\"Hello world.\");

How t

4条回答
  •  余生分开走
    2021-02-01 05:28

    Clojure comes with a logging core library in tools.logging. Add [org.clojure/tools.logging "0.2.3"] to your leiningen project.clj and run $lein deps as usual.

    Once you use the library you can start logging away

    (use 'clojure.tools.logging)
    (warn "something bad happened") 
    

    Now you can also access the logger object and set the required fields, refer to the following article for this (written for the older contrib-lib but the same ideas apply):

    http://www.paullegato.com/blog/setting-clojure-log-level/

提交回复
热议问题