Please help me filter third-party logging for Apache Log4j in my Java application

I use third-party banks that add their own logs to their Java application log file, I do not want to add these third-party logs to my log file, since the log file is very awkward and confusing.

I know this method, log4j.logger.org.springframework.jdbc.core.JdbcTemplate = OFF to disable logging in this particular org.springframework.jdbc.core.JdbcTemplate package in my lo4j.properties, but I have a lot of problem such cans added to my application, and therefore, you do not want to write manually for each package associated with the can.

Also, if new banks are added again, I have to add this configuration to the log4j.properties file.

+2
source share
2 answers

you can destroy whole librabries, as in

log4j.logger.org.springframework=OFF

or you can disable logging for the root registrar itself and enable it for the classes / packages you are interested in

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

this will allow you to keep a DEBUG journal for all subpackages and classes under com.your-package

Look at logging hierarchies in Log4j intro

+8
source

For someone still puzzled by this, I used spring 4 with log4j2. Spring 4 seems to only check log4j, not log4j2.xml.

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

Hope this helps someone else

0
source

All Articles