请帮助我在我的Java应用程序中过滤掉Apache Log4j的第三方日志。[英] Please help me Filtering out Third Party Logging for Apache Log4j in my Java Application

本文是小编为大家收集整理的关于请帮助我在我的Java应用程序中过滤掉Apache Log4j的第三方日志。的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我正在使用第三方罐子,这些罐子在我的Java应用程序的日志文件中附加了自己的日志,我不想在日志文件中附加这些第三方日志,因为它使日志文件非常笨拙且令人困惑.

我知道这种方法,log4j.logger.org.springframework.jdbc.core.core.jdbctemplate = off以关闭此特定软件包org.springframework.jdbc.core.core.core.jdbctemplate in my lo4j.properties,但问题我的应用程序中是否添加了许多这样的罐子,因此,要避免为与Jar相关的每个软件包手动写作.

另外,如果再次添加任何新罐子,我必须在我的log4j.properties文件中附加此配置.

推荐答案

您可以像

中的整个库.
log4j.logger.org.springframework=OFF

,或者您可以关闭根记录器本身的日志记录,并为您的兴趣的类/套餐启用它

log4j.rootLogger=OFF
log4j.logger.com.your-package=DEBUG, yourappender

这将启用com.your-package

下所有子弹和类的调试记录

查看 log4j Into

其他推荐答案

对于仍然被此仍然陷入困境的其他任何人,我都使用log4j2的Spring 4.春季4似乎仅检查log4j,而不是log4j2.xml.

我在我的资源中添加了一个log4j.xml文件(以及log4j2.xml),这对我有用.

希望它能帮助别人

本文地址:https://www.itbaoku.cn/post/1574816.html

问题描述

I am using Third Party jars which are appending their own logs in my Java Application's Log file , I don't want to append those third party logs in my log file as it makes log file very clumsy and confusing.

I know this method, log4j.logger.org.springframework.jdbc.core.JdbcTemplate=OFF to turn off the logging in this particular package org.springframework.jdbc.core.JdbcTemplate in my lo4j.properties, but the problem is I have many such jars added in my application and hence , want to avoid writing manually for each package associated with the jar.

Also if any new jars are added again I have to append this configuration in my log4j.properties file.

推荐答案

you can takedown whole librabries as in

log4j.logger.org.springframework=OFF

or you can turn off logging for the root logger itself and enable it for classes/packages of your interest

log4j.rootLogger=OFF
log4j.logger.com.your-package=DEBUG, yourappender

this will enable DEBUG logging for all subpackages and classes under com.your-package

look at Logging Hierarchies at Log4j intro

其他推荐答案

For anyone else still stumped by this, I was using spring 4 with log4j2. Spring 4 seems to only check for log4j, not log4j2.xml.

I added a log4j.xml file (as well as log4j2.xml) to my resources and that worked for me.

Hope it helps someone else