logback 生成日志时日志名称为XXX_IS_UNDEFINED

需要将日志打印在本项目中,于是调整logback.xml中日志生成路径,并在application.propeties中添加了变量。。结果读取不到。并且生成的log目录为XXX_IS_UNDEFINED。

主要问题就是没有读取到application.properties文件,所以解决办法为在logback.xml中添加一个属性

<property resource="application.properties" />

application.properties:

loggingroot  = ${user.dir}/output

logback.xml如下:

 
<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.logfileNamePattern>
            <maxHistory>7maxHistory>
            <maxFileSize>50MBmaxFileSize>
            <totalSizeCap>20GBtotalSizeCap>
        rollingPolicy>
    appender>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}pattern>
            <charset>utf8charset>
        encoder>
    appender>

    <root level="INFO">
        <appender-ref ref="CONSOLE" />
        <appender-ref ref="APPLICATION" />
    root>

configuration>

你可能感兴趣的:(java-web)