How to disable loggers of a class or of whole package?

In Log4j you can specify a logging level for specified package, class or logger identified by string. You just simply write this in log4j.properties file:

log4j.logger.<your package> = DEBUG|INFO|OFF|WARN...

Use of SimpleLog from Commons Logging requires two configuration files unless you are using some system properties. The files are: commons-logging.properties and simplelog.properties. The log level properties you have indicated should be placed in simplelog.properties like:

org.apache.commons.logging.simplelog.log.foo=warn

where "foo" is the logger name. Generally, this is the package or package and class name. In the following example, everything under the com.stackoverflow.utils package is set to info whereas com.stackoverflow.servlet.Dispatcher is specifically set to warn:

org.apache.commons.logging.simplelog.log.com.stackoverflow.utils=info 
org.apache.commons.logging.simplelog.log.com.stackoverflow.servlet.Dispatcher=warn 

The commons-logging.properties file should contain:

org.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog

Documentation here and here.


You should use:

log4j.logger.foo = OFF

Please note that "foo" does not need to be a package, or a class, but is an arbitrary String. We e.g. have a logger named "SQL" that is called from many classes.


If you use Spring Boot, you may set to OFF in application.properties file, by using logging.level.<package-or-class-name>=OFF Example:

logging.level.org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer=OFF

Reference: https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.logging.log-levels