开发者

log4j and Commons Logging co-existing

开发者 https://www.devze.com 2022-12-08 07:04 出处:网络
In my application I\'m using log4j and some 3rd party jars. One of those 3rd party jars is using Commons Logging. Now whenever I use classes from that 3rd party jar, somehow the log message is handled

In my application I'm using log4j and some 3rd party jars. One of those 3rd party jars is using Commons Logging. Now whenever I use classes from that 3rd party jar, somehow the log message is handled by two separate appenders. For example:

  • in my log4j.properties I have specified:

    • log4j.logger.myClass=DEBUG, serverFile, defaultSTDOUT, where serverFile is a org.apache.log4j.RollingFileAppender and defaultSTDOUT is org.apache.log4j.ConsoleAppender
  • in my code I do Logger logger = Logger.getLogger(myClass.class) and then I ue it li开发者_开发技巧ke logger.debug("debug message")

  • in console I see

DEBUG [2009-10-14 16:08:34,415] - debug message

51215 [Thread-13] DEBUG myClass - debug message

The first line is mine and the second line is probably there because of that 3rd party jar. How can I ensure that only my log message are shown?


It seems that specifying log4j.additivity for my logger did the job.

0

精彩评论

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