需要将日志打印在本项目中,于是调整logback.xml中日志生成路径,并在application.propeties中添加了变量。。结果读取不到。并且生成的log目录为XXX_IS_UNDEFINED。
主要问题就是没有读取到application.properties文件,所以解决办法为在logback.xml中添加一个属性
<property resource="application.properties" />
application.properties:
loggingroot = ${user.dir}/output
logback.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
<property resource="application.properties" />
<property name="APP_NAME" value="demo" />
<property name="LOG_PATH" value="${loggingRoot}/logs" />
<property name="LOG_FILE" value="${LOG_PATH}/application.log" />
<appender name="APPLICATION"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>${LOG_FILE}</file>
<encoder>
<pattern>${FILE_LOG_PATTERN}</pattern>
</encoder>
<rollingPolicy
class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>${LOG_FILE}.%d{yyyy-MM-dd}.%i.log</fileNamePattern>
<maxHistory>7</maxHistory>
<maxFileSize>50MB</maxFileSize>
<totalSizeCap>20GB</totalSizeCap>
</rollingPolicy>
</appender>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
<charset>utf8</charset>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="CONSOLE" />
<appender-ref ref="APPLICATION" />
</root>
</configuration>