Gradle java.util.logging.Logger output in unit tests

 ̄綄美尐妖づ 提交于 2020-01-04 01:29:08

问题


Sorry, this is probably a very simple question.

I am using gradle for my development environment. It works quite well!

I have written a simple unit test that uses HtmlUnit and my own package.

For my own package, I use java.util.Logger.

HtmlUnit seems to use commons logging.

I would like to see console output of my logging messages from java.util.Logger

However, it seems that even messages at the info level are not displayed in my Unit Test Results GUI (System.err link), although the HtmlUnit messages are all displayed.

Please let me know if you have suggestions.

Thank you! Misha


回答1:


Ok. I figured it out. It was quite odd.

Namely, if I initialize the logger outside of any methods:

class foo {
   def log=Logger.getLogger(this.class.name)
}

log output is not seen when I write a test.

However, if I initialize the logger inside the constructor

class foo {
   def log
   foo() {
      log=Logger.getLogger(this.class.name)
   }
}

Then it works fine. Odd...

Thank you! Misha




回答2:


Bridging logging systems from library's that use their own is complicated. Why not use slf4j's bridging JAR's? They will redirect old calls to commons logging to it's own logging system which YOU design against.

Take a look at http://www.slf4j.org/legacy.html



来源:https://stackoverflow.com/questions/2991360/gradle-java-util-logging-logger-output-in-unit-tests

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