首页 > 解决方案 > Springboot如何在服务器重启时轮换日志文件

问题描述

Springboot如何在服务器重启时轮换日志文件。

我有以下条目

# LOGGING
logging.level.org.springframework.web=WARN
logging.level.org.hibernate=WARN
logging.file=/var/log/apps/myapp.log

我在这里找不到任何细节:

https://docs.spring.io/spring-boot/docs/1.5.9.RELEASE/reference/html/common-application-properties.html

标签: javaspring-bootlog4j

解决方案


根据 application.properties 中有关日志文件的以下链接,以下是配置。

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html

logging.file.max-history=0 # Maximum of archive log files to keep. Only supported with the default logback setup.
logging.file.max-size=10MB # Maximum log file size. Only supported with the default logback setup.

除了上述之外,您还可以根据配置的服务器检查下面的配置。

server.tomcat.accesslog.rotate=true # Whether to enable access log rotation.
server.undertow.accesslog.rotate=true # Whether to enable access log rotation.

我建议将 Slf4j 与 logback 一起使用。您需要配置 logback.xml 并且可以配置滚动文件附加程序。


推荐阅读