先在maven裏把spring-boot-starter裏的spring-boot-starter-logging依賴去掉html
<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的依賴web
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
在application.yml裏配置日誌設置文件spring
logging:
config: classpath:log4j2.properties
log4j2.properties內容apache
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