问题
I am using apache.commons.logging, for now I wanted to use SimpleLog implementation, but when changed the level, loggers from libraries come out. I want it to turn it off.
Is there a easy way to change log level for whole package (Can log4j do that) ?
I have tried to set
org.apache.commons.logging.simplelog.log.foo=fatal
in simplelog property files to disable (setting to fatal is OK) foo logger, but it doesn't works. (foo is a name of logger that appears in output : [INFO] foo - Message).
回答1:
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...
回答2:
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.
回答3:
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
回答4:
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.
来源:https://stackoverflow.com/questions/4972954/how-to-disable-loggers-of-a-class-or-of-whole-package