spring-210729-01—Spring5新功能-整合日志框架
Spring5新功能特性地址:https://www.cntofu.com/book/95/33-what-new-in-the-spring-framework.md
特点:
整个Spring5框架基于Java8,
运行时兼容JDK9,
许多不建议使用的类和方法在代码库中删除
Spring 5.0框架自带了通用的日志封装
Spring5已经移除了Log4jConfigListener,官方建议使用Log4j2
Spring5框架整合Log4j2
第一步:引入Log4j2相关jar包
第二步:创建log4j2.xml(这个配置文件固定的)
log4j2.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration status="INFO">
<appenders>
<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</console>
</appenders>
<loggers>
<root level="info">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>
日志手动输出
TestLog.java
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestLog {
private static final Logger log = LoggerFactory.getLogger(TestLog.class);
public static void main(String[] args) {
log.info("hello log4j2");
log.warn("hello log4j2");
}
}
![](https://img-blog.csdnimg.cn/img_convert/b931f575122cc1634ef38bd84186694f.png)