65
4

4 回答 4

110

在 Log4j 中,您可以为由字符串标识的指定包、类或记录器指定日志记录级别。您只需将其写入 log4j.properties 文件:

log4j.logger.<your package> = DEBUG|INFO|OFF|WARN...
于 2011-02-11T19:16:53.897 回答
20

你应该使用:

log4j.logger.foo = OFF

请注意,“foo”不需要是包或类,而是任意字符串。例如,我们有一个名为“SQL”的记录器,它被许多类调用。

于 2011-02-11T19:28:42.213 回答
12

如果你使用 Spring Boot,你可以OFF在 application.properties 文件中设置,使用logging.level.<package-or-class-name>=OFF示例:

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

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

于 2017-01-20T08:49:39.857 回答
1

除非您使用某些系统属性,否则使用 Commons Logging 中的 SimpleLog 需要两个配置文件。这些文件是:commons-logging.properties 和 simplelog.properties。您指示的日志级别属性应放在 simplelog.properties 中,例如:

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

其中“foo”是记录器名称。通常,这是包或包和类名。在以下示例中, com.stackoverflow.utils 包下的所有内容都设置为info而 com.stackoverflow.servlet.Dispatcher 专门设置为warn

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

commons-logging.properties 文件应包含:

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

此处此处的文档。

于 2011-02-11T20:29:50.550 回答