<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <property name="log_path" value="logs"/>
  <!--  参数  -->
  <springProperty name="app_name" source="spring.application.name"/>
  <springProperty name="app_instance_id" source="eureka.instance.instance-id"/>

  <springProperty name="rabbitmq_host" source="spring.rabbitmq.host"/>
  <springProperty name="rabbitmq_vhost" source="spring.rabbitmq.virtual-host"/>
  <springProperty name="rabbitmq_username" source="spring.rabbitmq.username"/>
  <springProperty name="rabbitmq_password" source="spring.rabbitmq.password"/>



  <!-- 控制台日志 -->
  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level | %X{trace_id} | %X{span_id} | [%thread] %-5level %logger{36} : %msg%n</pattern>
      <charset>UTF-8</charset>
    </encoder>
  </appender>

  <!--  本地日志文件 -->
  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${log_path}/${app_name}.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>${log_path}/${app_name}-%d{yyyy-MM-dd}.%i.log</fileNamePattern>
      <maxHistory>10</maxHistory>
      <maxFileSize>50MB</maxFileSize>
    </rollingPolicy>
    <append>true</append>
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level | %X{trace_id} | %X{span_id} | [%thread] %-5level %logger{36} : %msg%n</pattern>
      <charset>UTF-8</charset>
    </encoder>
  </appender>

  <!--  日志发送到消息队列RabbitMQ ，接入ELK-->
  <appender name="RabbitMQ" class="org.springframework.amqp.rabbit.logback.AmqpAppender">
    <!--Layout（纯文本）而不是格式化的JSON -->
    <layout>
      <pattern>
        {
        "appName":"${app_name}",
        "appInstance":"${app_instance_id}",
        "date":"%d{yyyy-MM-dd HH:mm:ss.SSS}",
        "thread":"[%thread]",
        "level":"%-5level",
        "logger":"%logger{36}",
        "msg":"%msg"
        }
      </pattern>
    </layout>
    <host>${rabbitmq_host}</host>
    <port>5672</port>
    <username>${rabbitmq_username}</username>
    <password>${rabbitmq_password}</password>
    <virtualHost>${rabbitmq_vhost}</virtualHost>
    <!--  消息队列配置  -->
    <declareExchange>false</declareExchange>
    <exchangeType>direct</exchangeType>
    <exchangeName>logs.direct</exchangeName>
    <routingKeyPattern>logback</routingKeyPattern>
    <generateId>true</generateId>
    <durable>false</durable>
    <charset>UTF-8</charset>
    <deliveryMode>NON_PERSISTENT</deliveryMode>
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>info</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>

  <logger name="org.hibernate.engine.spi.QueryParameters" level="DEBUG"/>
  <logger name="org.hibernate.engine.query.spi.HQLQueryPlan" level="DEBUG"/>
  <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE"/>
<!--  <logger name="com.zaxxer.hikari.pool.HikariPool" level="DEBUG"/>-->
  <logger name="net.northking" level="DEBUG"/>

  <root level="INFO">
    <appender-ref ref="STDOUT"/>
    <appender-ref ref="FILE"/>
<!--    <appender-ref ref="RabbitMQ"/>-->
  </root>
</configuration>