先在maven里把spring-boot-starter里的spring-boot-starter-logging依赖去掉
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
添加log4j2的依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
在application.yml里配置日志设置文件
logging:
config: classpath:log4j2.properties
log4j2.properties内容
status = warn
name = MyApp
filter.threshold.type = ThresholdFilter
filter.threshold.level = debug
appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %-d{yyyy-MM-dd HH:mm:ss} [ %-5p ] %m (%c:%L)%n
appender.rolling.type = File
appender.rolling.name = log
appender.rolling.append = true
appender.rolling.fileName = d:\test1.log
appender.rolling.layout.type = PatternLayout
appender.rolling.layout.pattern = %-d{yyyy-MM-dd HH:mm:ss} [ %-5p ] %m (%c:%L)%n
rootLogger.level = debug
rootLogger.appenderRef.stdout.ref = STDOUT
rootLogger.appenderRef.log.ref = log