<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~  Copyright 1999-2019 Seata.io Group.
  ~
  ~  Licensed under the Apache License, Version 2.0 (the "License");
  ~  you may not use this file except in compliance with the License.
  ~  You may obtain a copy of the License at
  ~
  ~       http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~  Unless required by applicable law or agreed to in writing, software
  ~  distributed under the License is distributed on an "AS IS" BASIS,
  ~  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~  See the License for the specific language governing permissions and
  ~  limitations under the License.
  -->

<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <!-- 定义日志文件的存储地址 -->
    <springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue=""/>
    <property name="LOG_HOME" value="logs/${spring.application.name}"/>
    <!-- 控制台输出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!--与ThresholdFilter的区别,允许onmatch-->
            <!--设置日志级别 接收info级别的日志-->
            <level>DEBUG</level>
        </filter>
    </appender>
    <!-- 按照每天生成日志文件 DEBUG以上级别的日志,仅用于测试环境,正式环境为info级别以上的日志 -->
    <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!-- 文件路径 -->
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--历史日志文件输出的文件名 -->
            <FileNamePattern>${LOG_HOME}/wvp-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
            <maxFileSize>20MB</maxFileSize>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!--与ThresholdFilter的区别,允许onmatch-->
            <!--设置日志级别 接收info级别的日志-->
            <level>DEBUG</level>
        </filter>
    </appender>
    <!-- 生成 error格式日志开始 -->
    <appender name="RollingFileError" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--历史日志文件输出的文件名 -->
            <FileNamePattern>${LOG_HOME}/error-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
            <maxFileSize>20MB</maxFileSize>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
            <!--设置日志级别,过滤掉info日志,只输入error日志-->
            <level>WARN</level>
            <!--            <onMatch>ACCEPT</onMatch>  &lt;!&ndash; 用过滤器，只接受ERROR级别的日志信息，其余全部过滤掉 &ndash;&gt;-->
            <!--            <onMismatch>DENY</onMismatch>-->
        </filter>
    </appender>
    <!-- 生成SIP日志追加 -->
    <appender name="sipRollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <!--历史日志文件输出的文件名 -->
            <FileNamePattern>${LOG_HOME}/sip-%d{yyyy-MM-dd}.%i.log</FileNamePattern>
            <!--日志文件保留天数 -->
            <MaxHistory>30</MaxHistory>
            <maxFileSize>50MB</maxFileSize>
        </rollingPolicy>
        <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
            <!--格式化输出：%d表示日期，%thread表示线程名，%-5level：级别从左显示5个字符宽度%msg：日志消息，%n是换行符 -->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50}:%L - %msg%n</pattern>
        </encoder>
    </appender>
    <!-- 日志输出级别 -->
    <root level="INFO">
        <appender-ref ref="STDOUT"/>
    </root>
    <!-- name:用来指定受此logger约束的某一个包或者具体的某一个类 -->
    <!--    <logger name="com.example.wvpdisassembly" level="debug" additivity="true">-->
    <!--        <appender-ref ref="RollingFileError"/>-->
    <!--        <appender-ref ref="RollingFile"/>-->
    <!--    </logger>-->
    <!--    <logger name="com.example.wvpdisassembly.gb28181" level="debug" additivity="true">-->
    <!--        <appender-ref ref="RollingFileError"/>-->
    <!--        <appender-ref ref="sipRollingFile"/>-->
    <!--    </logger>-->
    <!-- Context listeners -->
    <contextListener class="io.seata.server.logging.listener.SystemPropertyLoggerContextListener"/>

    <!-- The conversion rules are copied from `defaults.xml` in the `spring-boot-xxx.jar` -->
    <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
    <conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
    <conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
    <!-- The custom conversion rules -->
    <conversionRule conversionWord="wEx2" converterClass="io.seata.server.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/>

    <!-- common properties -->
    <springProperty name="PORT" source="server.port" defaultValue="7091"/>
    <springProperty name="APPLICATION_NAME" source="spring.application.name" defaultValue="seata-server"/>


    <!-- console-appender -->
    <include resource="logback/console-appender.xml"/>

    <!-- file-appender -->
    <include resource="logback/file-appender.xml"/>

    <!-- logstash-appender: off by default -->
    <!--<include resource="logback/logstash-appender.xml"/>-->

    <!-- kafka-appender: off by default -->
    <!--<include resource="logback/kafka-appender.xml"/>-->

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

        <!-- file-appender -->
        <appender-ref ref="FILE_ALL"/>
        <appender-ref ref="FILE_WARN"/>
        <appender-ref ref="FILE_ERROR"/>

        <!-- logstash-appender: off by default -->
        <!--<appender-ref ref="LOGSTASH"/>-->

        <!-- kafka-appender: off by default -->
        <!--<appender-ref ref="KAFKA"/>-->
    </root>
</configuration>
