<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="true" scanPeriod="1 seconds">
    <include resource="logback-default.xml"/>
    <contextName>logback</contextName>
    <springProperty scope="context" name="logStore" source="spring.application.name"/>
    <property name="log.path" value="/var/logs/${logStore}"/>

    <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%date{yyyy-MM-dd HH:mm:ss.SSS} [%X{X-Request-Id}] [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="localFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/app.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/%d{yyyy-MM-dd,aux}/app-%d{yyyy-MM-dd}.%i.log
            </fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <!-- 保留最近60天的日志 -->
            <maxHistory>60</maxHistory>
        </rollingPolicy>
        <encoder>
            <pattern>%date{HH:mm:ss.SSS} [%X{X-Request-Id}] [%thread] %-5level %logger - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="asyncFileAppender" class="ch.qos.logback.classic.AsyncAppender">
        <queueSize>10000</queueSize>
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="file"/>
    </appender>

    <!-- 读取配置文件信息(交由各项目指定) -->
    <property name="active" value="${spring.profiles.active:-test}" />
    <property name="active" value="${env:-test}" />
    <springProperty scope="context" name="springEnv" source="spring.profiles.active" defaultValue="${active:-test}" />
    <springProperty scope="context" name="appEnv" source="server.application.logEnv" defaultValue="${springEnv:-test}" />
    <springProperty scope="context" name="appId" source="spring.application.name" defaultValue="localhost" />

    <!--为了防止进程退出时，内存中的数据丢失，请加上此选项-->
    <shutdownHook class="ch.qos.logback.core.hook.DelayingShutdownHook"/>

    <logger name="org.hibernate" level="ERROR" />
    <logger name="org.apache" level="ERROR" />
    <logger name="ch.qos.logback" level="WARN" />
    <logger name="org.elasticsearch" level="ERROR" />
    <logger name="org.mongodb.driver" level="INFO" />
    <logger name="springfox.documentation" level="WARN" />
    <logger name="com.aliyun.openservices.log" level="INFO" />
    <logger name="com" level="INFO"/>
    <logger name="top" level="INFO"/>
    <logger name="net" level="ERROR"/>
    <logger name="org" level="INFO"/>
    <logger name="io" level="INFO"/>
    <logger name="springfox" level="INFO"/>
    <logger name="Validator" level="INFO"/>
    <logger name="org.springframework" level="INFO"/>


    <springProfile name="test,prod">
        <root level="DEBUG">
            <appender-ref ref="console"/>
            <appender-ref ref="localFile"/>
        </root>
    </springProfile>

    <springProfile name="local">
        <root level="DEBUG">
            <appender-ref ref="console"/>
        </root>
    </springProfile>

</configuration>