我的 spring-boot 应用程序创建了一个日志文件,其名称logging.path_IS_UNDEFINEDlogging.file_IS_UNDEFINED.log
清楚地表明在 logback 初始化日志配置logging.path
时logging.file
未设置属性。这听起来像是这个的副本但是,我尝试了该帖子中所有建议的解决方案。我正在使用 spring-boot 2.0 版
应用程序-dev.yaml
spring:
main:
allow-bean-definition-overriding: true
application:
name: my-application
logging:
path: /var/logs/${spring.application.name}/
file:
max-size: 10MB
max-history: 5
弹簧logback.xml
<?xml version="1.0" encoding="UTF-8"?>
<Configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<include resource="org/springframework/boot/logging/logback/file-appender.xml"/>
<property name="logging.pattern.console" value="%d{HH:mm:ss.SSS} [%t] %-5level %X{transactionId} %logger{36} - %msg%n"/>
<property name="logging.file.roll-pattern" value="application-%d{yyyy-MM-dd}-%i.log"/>
<springProfile name="dev">
<property resource="application-dev.yaml" />
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
<logger name="org.springframework" level="INFO"/>
<logger name="com.myapp" level="DEBUG"/>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${logging.path}${logging.file}.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- daily rollover -->
<fileNamePattern>${logging.path}${logging.file}.%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>${FILE_LOG_PATTERN}</pattern>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
</springProfile>
</Configuration>