解决SpringBoot+LogBack LOG_PATH_IS

2019-03-27  本文已影响0人  南岩飞雪

原因

application-dev.yml

logging:
  path: /home/admin/xxx/logs
spring:
  profiles: dev

logback-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <springProperty name="LOG_PATH" source="logging.path" defaultValue="/home/admin/xxx/logs" />

    <springProfile name="default">
        <include resource="logback/logback-dev.xml" />
    </springProfile>
    <springProfile name="dev">
        <include resource="logback/logback-dev.xml" />
    </springProfile>

</configuration>

logback-dev.xml

<?xml version="1.0" encoding="UTF-8"?>
<!-- Logback Configuration.  -->
<included>

    <appender name="FILE"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
        <encoder>
            <pattern><![CDATA[
[%d{yyyy-MM-dd HH:mm:ss}] [traceid=%X{traceId},uri=%X{uri}]  %-5level %logger{35} - %m%n
            ]]></pattern>
            <charset>utf8</charset>
        </encoder>
        <file>${LOG_PATH}/xxx.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${LOG_PATH}/xxx.%d{yyyy-MM-dd}-%i.log</fileNamePattern>
            <MaxHistory>5</MaxHistory>
            <timeBasedFileNamingAndTriggeringPolicy
                    class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>500MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
    </appender>

    <appender name="ERROR-FILE"
              class="ch.qos.logback.core.rolling.RollingFileAppender">
    ....
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <logger name="com.xxx" additivity="false" >
        <level value="info" />
        <appender-ref ref="FILE" />
        <appender-ref ref="ERROR-FILE" />
    </logger>

    <root>
        <level value="info" />
        <appender-ref ref="FILE" />
        <appender-ref ref="ERROR-FILE" />
    </root>
</included>

参考

SpringBoot with LogBack creating LOG_PATH_IS_UNDEFINED folder

上一篇 下一篇

猜你喜欢

热点阅读