1、pom引入log4j2依赖,之前暴露出log4j2漏洞,建议版本号高一些
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>2.17.1</version>
</dependency>
2、配置log4j2.properties
略
3、排除springboot中自带的log包 (很重要)
如果不排除,会导致日志无法打印到日志文件中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>spring-boot-starter-logging</artifactId>
<groupId>org.springframework.boot</groupId>
</exclusion>
</exclusions>
</dependency>