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

旧街凉风 提交于 2019-11-27 03:49:04

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...
Daniel

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. Example:

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

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

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.

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