[英]Is it possible to modify log appender parameters via application.properties in Spring Boot?
[英]Issues with Log Levels in Spring Boot application.properties
我在 Spring Boot 应用程序中使用 Log4J 2 并尝试通过 application.properties 配置几个基本的日志记录选项。
我在我的控制器类中设置了一个记录器,就像这样。
package guru.springframework.controllers;
- - - -
@Controller
public class IndexController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/")
String index(){
logger.debug("This is a debug message");
logger.info("This is an info message");
logger.warn("This is a warn message");
logger.error("This is an error message");
return "index";
}
}
在 application.properties 中,我有以下属性。
logging.level.guru.springframework.controllers=DEBUG
logging.level.org.springframework.web=INFO
logging.file=logs/spring-boot-logging.log
当我启动应用程序时,Spring 内部日志消息在控制台中以 INFO 级别记录。 这是logging.level.org.springframework.web属性所预期的。 但是,当控制器被调用时,只会记录info()和 lower 的消息。 将logging.level.guru.springframework.controllers属性设置为 DEBUG,为什么没有记录debug()方法的消息。 如果我将以下内容添加到 application.properties。
logging.level.root=ERROR
现在,Spring 启动时没有消息发送到控制台(显然这次错误级别已被拾取)。 类似地,控制器仅发出error()方法消息。 那么,从 application.properties 中获取级别是否有任何特定的优先级。
有没有办法为不同的包(比如控制器包)设置不同的级别,独立于 application.properties 中为logging.level.root和logging.level.org.springframework.web指定的级别。
我不想使用任何其他外部配置文件。
您正在使用包含bug的旧版本 Spring Boot (1.2.4.RELEASE)。 它在 1.2.6.RELEASE 中得到修复,但我建议升级到 1.2.8.RELEASE(如果您需要坚持使用 1.2.x),或者更好的是升级到 1.3.3.RELEASE(最新版本)写作时间)。 您可以通过更新您在项目 pom 中使用的spring-boot-starer-parent
版本来升级:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.