suppress output from `clojure.tools.logging`

旧时模样 提交于 2019-12-13 02:11:05

问题


I'm having difficulty hiding the output of clojure.tools.logging a library is using. The library is logging an error and this causes a stacktrace on stderr but it's not an error-level message for me and I can't figure out a way to hide it. I use timbre for my own application so I guess capturing the output and re-logging it as a warning or just a debug would be ideal, but for now I just need the stacktrace noise gone.

I've tried rebinding err to out and then nesting the body within a with-out-str.

I've tried a log4j.properties file on the CLASSPATH with the root logger's default level set to fatal.

I've tried an hours worth of other miscellanea. The logging was introduced to the library here: https://github.com/apa512/clj-rethinkdb/commit/5587bdadaed663fcab3b7c616840dfffec84569a and I can't figure out how to capture it's logger and set it's level or why setting the root logger's level in my log4j.properties is not working.

Any suggestions before I simply do a java -jar app 2> /dev/null ?


回答1:


The clojure.tools.logging project dynamically loads a logging implementation based on what dependencies are available on the classpath. Unless you already have SLF4J, Commons Logging, or Log4j as a project dependency, tools.logging will fall back to using java.util.logging (which directs all output to System.out in the absence of any configuration) and putting log4j.properties on your classpath will have no effect.

If you want output from tools.logging redirected to Timbre, I'd suggest adding [org.slf4j/slf4j-api] to your project dependencies and then using the slf4j-timbre adapter.



来源:https://stackoverflow.com/questions/33742124/suppress-output-from-clojure-tools-logging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!