本文主要是介绍Spring入门学习(三)logback配置按天打日志,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Spring入门学习(三)logback配置按天打日志
添加log的依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId>
</dependency>
logback的配置文件logback.xml
在根目录创建logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<configuration><appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"><rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"><!-- daily rollover --><fileNamePattern>SpringPro.%d{yyyy-MM-dd}.log</fileNamePattern><!-- keep 30 days' worth of history capped at 3GB total size --><maxHistory>30</maxHistory><totalSizeCap>3GB</totalSizeCap></rollingPolicy><encoder><pattern>%d %-4relative [%thread] %-5level %logger{35} - %msg%n</pattern></encoder></appender><root level="DEBUG"><appender-ref ref="FILE" /></root>
</configuration>
spring项目的配置文件
在根目录创建application.properties
#logback log path
logging.config=logback.xml
效果
代码
https://gitee.com/pangPython/SpringPro
这篇关于Spring入门学习(三)logback配置按天打日志的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!