log4j 和 Commons Logging 共存

发布于 2024-08-07 13:28:30 字数 653 浏览 3 评论 0原文

在我的应用程序中,我使用 log4j 和一些第三方 jar。其中第 3 方 jar 之一正在使用 Commons Logging。现在,每当我使用第三方 jar 中的类时,日志消息都会以某种方式由两个单独的附加程序处理。 例如:

  • 在我的 log4j.properties 中我已指定:

    • log4j.logger.myClass=DEBUG, serverFile, defaultSTDOUT,其中 serverFile 是 org.apache.log4j.RollingFileAppender,defaultSTDOUT 是 org.apache.log4j.ConsoleAppender
  • 我的代码我做 Logger logger = Logger.getLogger(myClass.class) 然后我像 logger.debug("debug message")

  • in console I see

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

51215 [Thread- 13] DEBUG myClass - 调试消息

第一行是我的,第二行可能是因为第三方 jar 的缘故。 如何确保只显示我的日志消息?

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 like 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女七分熟 2024-08-14 13:28:30

看来为我的记录器指定 log4j.additivity 就完成了这项工作。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文