来自供应商库的垃圾淹没了 log4j
如何才能最好地防止这些库淹没我自己的应用程序 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
供应商是否合理使用类别? 如果是这样,请将仅将其根类别设置为“错误”,并使其他一切保持正常。 这样你应该能够过滤掉他们的非错误消息,但仍然可以看到你自己的信息/调试/等。
这就是类别的大部分要点:)
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 :)
正如 Jon Skeet 的回答所建议的,您应该配置log4j 忽略供应商库中的类。 通常有一个名为
log4j.xml
的文件,可以将包名称和阈值类别打印出来,如下所示:看看 手册了解详细信息。
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:Take a look at the manual for details.
呃,如果所有其他方法都失败了,您可以扩展 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)