来自供应商库的垃圾淹没了 log4j

发布于 2024-07-30 01:30:23 字数 114 浏览 3 评论 0原文

如何才能最好地防止这些库淹没我自己的应用程序 log4j 总线? 我不想将所有内容都设置为“错误”,但按照这个速度,供应商库正在以大约每天 1 兆的速度淹没日志文件。 我不希望它向该文件记录任何内容......

How can I best prevent these libraries from flooding my own apps log4j bus? I do not want to set everything to ERROR, but at this rate the vendor library is flooding up the log file at a rate of about a gig/day. I do not want it to log anything to this file...

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

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

发布评论

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

评论(3

油饼 2024-08-06 01:30:23

供应商是否合理使用类别? 如果是这样,请将仅将其根类别设置为“错误”,并使其他一切保持正常。 这样你应该能够过滤掉他们的非错误消息,但仍然可以看到你自己的信息/调试/等。

这就是类别的大部分要点:)

Is the vendor using categories reasonably? If so, set just their root category to ERROR and leave everything else as normal. That way you should be able to filter out their non-error messages but still see your own info/debug/etc.

That's most of the point of categories :)

來不及說愛妳 2024-08-06 01:30:23

正如 Jon Skeet 的回答所建议的,您应该配置log4j 忽略供应商库中的类。 通常有一个名为 log4j.xml 的文件,可以将包名称和阈值类别打印出来,如下所示:

   <category name="httpclient.wire">
      <priority value="INFO"/>
   </category>

   <category name="org.apache.commons.httpclient">
      <priority value="WARN"/>
   </category>

   <category name="org.hibernate">
      <priority value="DEBUG"/>
   </category>

   <category name="net.sf.jasperreports">
      <priority value="ERROR"/>
   </category>

看看 手册了解详细信息。

As suggested by Jon Skeet´s answer, you should configure log4j to ignore the classes from the vendor library. Usually there is a file named log4j.xml that one can put the package names and the threshold category to print like this:

   <category name="httpclient.wire">
      <priority value="INFO"/>
   </category>

   <category name="org.apache.commons.httpclient">
      <priority value="WARN"/>
   </category>

   <category name="org.hibernate">
      <priority value="DEBUG"/>
   </category>

   <category name="net.sf.jasperreports">
      <priority value="ERROR"/>
   </category>

Take a look at the manual for details.

懒猫 2024-08-06 01:30:23

呃,如果所有其他方法都失败了,您可以扩展 LogImpl 并将其注入一个属性到所有日志记录调用中,并在所有附加程序上设置 PropertyFilter。 但希望事情不会发展到这样的地步。

(请注意,这是来自 log4net - 我认为它的工作原理基本相同,但我只是从臀部拍摄)

Eh, if all else fails you could extend LogImpl and have it inject a property into all of your logging calls and set a PropertyFilter on all of your appenders. Hope it wouldn't come to that, though.

(mind you, this is coming from log4net - I assume it all works mostly the same, but I'm just shooting from the hip)

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