我需要滚动日志,所以我创建了一个“logback-spring.xml”文件并将其放在src / main / resources中。工作完美无瑕。
问题是执行器端点“/ logfile”不再有效,因为我已从“applications.yml”文件中删除了日志记录配置。 根据文档,需要设置“logging.path”或“logging.file”才能使“/ logfile”端点工作。然而,这似乎与我的新'xml配置冲突。
以下是我的logback-spring.xml配置:
<configuration debug="true" scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<property name="LOG_PATH" value="logs"/>
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive"/>
<appender name="RollingFile-Appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/bookingflow-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d %-5level [%thread] %logger : %msg%n</pattern>
</encoder>
</appender>
<appender name="Async-Appender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="RollingFile-Appender"/>
</appender>
<logger name="com.novasol.bookingflow.api" level="debug">
<appender-ref ref="Async-Appender"/>
</logger>
<springProfile name="production">
<logger name="com.novasol.bookingflow.api" level="error">
<appender-ref ref="Async-Appender"/>
</logger>
</springProfile>
</configuration>
任何指示赞赏。
亲切的问候 拉斯
答案 0 :(得分:4)
以下列方式解决:
在application.yml
中logging:
config:
classpath: "logback-spring.xml"
file: logs/bookingflow.log
“logback-spring.xml”:
<configuration debug="true" scan="true">
<include resource="org/springframework/boot/logging/logback/base.xml"/>
<property name="LOG_ARCHIVE" value="${LOG_PATH}/archive"/>
<appender name="RollingFile-Appender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_PATH}/${LOG_FILE}</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${LOG_ARCHIVE}/bookingflow-%d{yyyy-MM-dd}.log</fileNamePattern>
<maxHistory>30</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<encoder>
<pattern>%d %-5level [%thread] %logger : %msg%n</pattern>
</encoder>
</appender>
<appender name="Async-Appender" class="ch.qos.logback.classic.AsyncAppender">
<appender-ref ref="RollingFile-Appender"/>
</appender>
<logger name="com.novasol.bookingflow.api" level="debug">
<appender-ref ref="Async-Appender"/>
</logger>
<springProfile name="production">
<logger name="com.novasol.bookingflow.api" level="error">
<appender-ref ref="Async-Appender"/>
</logger>
</springProfile>
终于找到了解决方案:
需要指定以下内容
endpoints:
logfile:
external-file: logs/custom.log