如何在 Spring Boot 的 application.yml 中配置滚动文件 appender [英] How to configure rolling file appender within Spring Boot's application.yml
本文介绍了如何在 Spring Boot 的 application.yml 中配置滚动文件 appender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 Spring Boot 应用程序的 application.yml 中配置每日文件 appender?
Is is possible to configure a daily file appender within the application.yml of a Spring Boot application?
即文件名模式:myfile.%d{yyyy-MM-dd-HH-mm-ss}.log
i.e. filenamePattern: myfile.%d{yyyy-MM-dd-HH-mm-ss}.log
我的 application.yml 文件中有如下配置.
I have configuration such as the following in my application.yml file.
logging:
file: /mypath/myfile.log
level:
mypackage: INFO
谢谢
推荐答案
默认文件附加器基于大小(10MB).
The default file appender is size based (10MB).
在您的 logback.xml
中,只需按照 这里
In your logback.xml
just configure a TimeBasedRollingPolicy
as described here
即类似:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<appender name="ROLLIN" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.log</fileNamePattern>
</rollingPolicy>
</appender>
<root level="INFO">
<appender-ref ref="ROLLIN" />
</root>
<logger name="org.springframework.web" level="INFO"/>
</configuration>
这篇关于如何在 Spring Boot 的 application.yml 中配置滚动文件 appender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文