Please help me Filtering out Third Party Logging for Apache Log4j in my Java Application

旧巷老猫 提交于 2019-12-30 07:23:10

问题


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.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/12949856/please-help-me-filtering-out-third-party-logging-for-apache-log4j-in-my-java-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!