<?xml version="1.0" encoding="UTF-8" ?>

<configuration>
  <property name="LOG_PATH" value="/logs"/>
  <property name="LOG_FILE" value="${LOG_PATH}/smt.log"/>
  <property name="LOG_FILE_ERROR" value="${LOG_PATH}/smt_error.log"/>
  <property name="FILE_LOG_CHARSET" value="UTF-8"/>
  <property name="LOGBACK_ROLLINGPOLICY_FILE_NAME_PATTERN" value="${LOG_PATH}/smt.%d{yyyy-MM-dd}.%i.log.zip"/>
  <property name="LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE" value="1GB"/>
  <property name="LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP" value="50GB"/>
  <property name="LOGBACK_ROLLINGPOLICY_MAX_HISTORY" value="30"/>

  <!--springboot基础配置-->
  <include resource="org/springframework/boot/logging/logback/defaults.xml" />
  <include resource="org/springframework/boot/logging/logback/console-appender.xml" />
  <include resource="org/springframework/boot/logging/logback/file-appender.xml" />

  <!--错误日志-->
  <appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <encoder>
      <pattern>${FILE_LOG_PATTERN}</pattern>
      <charset>${FILE_LOG_CHARSET}</charset>
    </encoder>
    <file>${LOG_FILE_ERROR}</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
      <fileNamePattern>${LOG_PATH}/smt.%d{yyyy-MM-dd}.%i.error.log.zip</fileNamePattern>
      <cleanHistoryOnStart>${LOGBACK_ROLLINGPOLICY_CLEAN_HISTORY_ON_START:-false}</cleanHistoryOnStart>
      <maxFileSize>${LOGBACK_ROLLINGPOLICY_MAX_FILE_SIZE:-1GB}</maxFileSize>
      <totalSizeCap>${LOGBACK_ROLLINGPOLICY_TOTAL_SIZE_CAP:-50GB}</totalSizeCap>
      <maxHistory>${LOGBACK_ROLLINGPOLICY_MAX_HISTORY:-30}</maxHistory>
    </rollingPolicy>
    <!-- 只打印ERROR日志 -->
    <filter class="ch.qos.logback.classic.filter.LevelFilter">
      <level>ERROR</level>
      <onMatch>ACCEPT</onMatch>
      <onMismatch>DENY</onMismatch>
    </filter>
  </appender>

  <!--远程日志-->
  <appender name="SOCKET" class="cc.smtweb.framework.core.log.appender.SmtSocketAppender">
    <remoteHost>localhost</remoteHost>
    <port>21022</port>
    <reconnectionDelay>10000</reconnectionDelay>
  </appender>

  <!--数据库日志-->
  <!--ch.qos.logback.classic.db.DBAppender-->
  <appender name="DB" class="cc.smtweb.framework.core.log.appender.SmtDBAppender">
    <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource">
      <driverClass>com.mysql.cj.jdbc.Driver</driverClass>
      <url>jdbc:mysql://192.168.110.210:4418/lrjx?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;useSSL=false</url>
      <user>root</user>
      <password>Ncmz@2022_jjkj</password>
<!--      <url>jdbc:mysql://127.0.0.1:4408/lrjx?useUnicode=true&amp;characterEncoding=utf-8&amp;allowMultiQueries=true&amp;useSSL=false</url>-->
<!--      <user>root</user>-->
<!--      <password>Jujia_@)@!0427</password>-->
    </connectionSource>
    <filter class="cc.smtweb.framework.core.log.filter.DBFilter"/>
  </appender>

  <!--显示JDBC日志-->
  <logger name="org.springframework.jdbc.core" additivity="false" level="DEBUG" >
    <appender-ref ref="CONSOLE" />
  </logger>

  <root level="INFO">
    <appender-ref ref="CONSOLE" />
    <appender-ref ref="FILE" />
    <appender-ref ref="FILE-ERROR" />
    <appender-ref ref="SOCKET" />
    <appender-ref ref="DB" />
  </root>
</configuration>
