开发者

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

开发者 https://www.devze.com 2023-01-02 19:30 出处:网络
Sorry, this is probably a very simple question. I am using gradle for my development environment. It works quite well!

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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消