【问题标题】:Is there a way to use the default Springboot "/actuator/logfile" endpoint when using Logback's RollingFileAppender?使用 Logback RollingFileAppender 时,有没有办法使用默认的 Spring Boot“/actuator/logfile”端点?
【发布时间】:2019-02-08 13:35:37
【问题描述】:
我正在使用的 Springboot REST 服务器正在使用 Logback 的 RollingFileAppender 和 SizeAndTimeBasedRollingPolicy 记录文件。
我希望 spring 执行器的“日志文件”端点从最近的文件中返回日志,但是文件名会根据给定的文件名模式而变化。
除了使用 application.properties 中给出的文件或路径之外,日志文件执行器是否有其他方法可以访问日志文件?
【问题讨论】:
标签:
java
spring-boot
logback
spring-boot-actuator
rollingfileappender
【解决方案1】:
根据org.springframework.boot.actuate.autoconfigure.logging.LogFileWebEndpointAutoConfiguration.LogFileCondition
management:
endpoints:
web:
exposure:
include: logfile
endpoint:
logfile:
external-file: ${user.home}/temp/app.log
【解决方案2】:
在“文件”附加器配置部分的 logback 配置中,您必须具有类似的内容:
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>logs/logfile.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>logs/logfile.%d{yyyy-MM-dd}_%i.log</fileNamePattern>
<!-- keep 30 days' worth of history capped at 2GB total size -->
<maxHistory>30</maxHistory>
<maxFileSize>1GB</maxFileSize>
<totalSizeCap>2GB</totalSizeCap>
</rollingPolicy>
</appender>
您最近的日志文件将是 logfile.log,您可以在 app.properties 中定义,例如:
endpoints.logfile.external-file=logs/logfile.log
所有因大小限制而回滚的日志文件将根据模式重命名。