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

<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <!-- <pattern>%date %level [%thread] %logger{10} [%file:%line] %msg%n</pattern>-->
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} %X{sourceThread} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>./log/scheduler.log</file>

        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <!-- rollover every daily -->
            <fileNamePattern>./log/scheduler-%d{yyyy-MM-dd}.%i.log.zip</fileNamePattern>
            <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
                <!-- or whenever the file size reaches 50MB -->
                <maxFileSize>50MB</maxFileSize>
            </timeBasedFileNamingAndTriggeringPolicy>
            <maxHistory>5</maxHistory>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
            <!-- <totalSizeCap>2GB</totalSizeCap> -->
        </rollingPolicy>
        <encoder>
            <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{60} %X{sourceThread} - %msg%n</pattern>
        </encoder>
    </appender>

    <appender name="GateLogger" class="com.github.danielwegener.logback.kafka.KafkaAppender">
      <encoder class="com.github.danielwegener.logback.kafka.encoding.LayoutKafkaMessageEncoder">
        <layout class="ru.sbt.synapse.logback.FpjLayout">
          <bodyType>json</bodyType>                         <!-- указывается тип сообщения xml или json  -->
          <rqUIDPath>$..rqUID</rqUIDPath>                   <!-- указывается путь до rquid (case sensitive) в логируемых сообщениях xpath (//rqUID) или jsonpath ($..rqUID) -->
        </layout>
      </encoder>
      <deliveryStrategy class="com.github.danielwegener.logback.kafka.delivery.AsynchronousDeliveryStrategy"/>
      <topic>LOGGER.EVPT</topic>

      <producerConfig>client.id=test-noetcd-auth</producerConfig>
      <producerConfig>config.providers=decode</producerConfig>
      <producerConfig>config.providers.decode.class=ru.sbt.ss.kafka.DecryptionConfigProvider</producerConfig>
      <producerConfig>config.providers.decode.param.security.encoding.key=./ssl/secret.pass</producerConfig>
      <producerConfig>config.providers.decode.param.security.encoding.class=ru.sbt.ss.password.BaseEncryptor</producerConfig>

      <producerConfig>security.protocol=SSL</producerConfig>
      <producerConfig>ssl.endpoint.identification.algorithm=</producerConfig>
      <producerConfig>ssl.keystore.location=ssl/scheduler.jks</producerConfig>
      <producerConfig>ssl.truststore.location=ssl/scheduler.jks</producerConfig>

      <producerConfig>ssl.keystore.password=${dollar}{decode:xxx}</producerConfig>
      <producerConfig>ssl.truststore.password=${dollar}{decode:yyy}</producerConfig>
      <producerConfig>ssl.key.password=${dollar}{decode:zzz}</producerConfig>

      <producerConfig>bootstrap.servers=host:port,host:port</producerConfig>
      <appender-ref ref="STDOUT"/>
    </appender>

    <appender name="ASYNC_GateLogger" class="ch.qos.logback.classic.AsyncAppender">
        <appender-ref ref="GateLogger"/>
        <discardingThreshold>0</discardingThreshold>
        <queueSize>512</queueSize>
        <neverBlock>false</neverBlock>
    </appender>

    <logger name="ru.sbt.ss.reactive.stream.transformers.logging.MessageLogger" level="info" additivity="false" >
        <appender-ref ref="ASYNC_GateLogger"/>
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="file"/>
    </logger>

    <root level="info">
        <appender-ref ref="STDOUT"/>
        <appender-ref ref="file"/>
    </root>

</configuration>