<!--

    Copyright 2015-2018 Jeeva Kandasamy (jkandasa@gmail.com)
    and other contributors as indicated by the @author tags.

    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="2 minutes">

  <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>../logs/mycontroller.log</file>
    <encoder>
      <!-- <pattern>%date %level [%thread] [%logger:%line] %msg%n</pattern> -->
      <!-- Replace CR(\r) with string \r and LF(\n) with string \n-->
      <pattern>%date %level [%thread] [%logger:%line] %replace(%msg){'\r', '\\r'}%n</pattern>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <FileNamePattern>../logs/mycontroller_%i.log.zip</FileNamePattern>
      <MinIndex>1</MinIndex>
      <MaxIndex>5</MaxIndex>
    </rollingPolicy>
    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <MaxFileSize>5MB</MaxFileSize>
    </triggeringPolicy>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%date %level [%thread] [%logger:%line] %msg%n</pattern>
    </encoder>
  </appender>

  <appender name="GATEWAY_RAW_MESSAGE_APPENDER" class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator>
      <key>gateway_reference</key>
      <defaultValue>0_default</defaultValue>
    </discriminator>
    <sift>
      <appender name="fileAppender" class="ch.qos.logback.core.FileAppender">
        <file>../logs/raw_message_gw_${gateway_reference}.log</file>
        <encoder>
          <pattern>%date %replace(%replace(%msg){'\r', '\\r'}){'\n', '\\n'}%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
          <FileNamePattern>../logs/raw_message_gw_${gateway_reference}%i.log.zip</FileNamePattern>
          <MinIndex>1</MinIndex>
          <MaxIndex>5</MaxIndex>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
          <MaxFileSize>5MB</MaxFileSize>
        </triggeringPolicy>
      </appender>
    </sift>
  </appender>

  <logger level="INFO" name="com.j256.ormlite" />
  <logger level="INFO" name="org.apache.http" />
  <logger level="INFO" name="org.jboss.resteasy.core" />
  <logger level="WARN" name="com.j256.ormlite.table.TableUtils" />
  <logger level="WARN" name="com.xeiam.sundial" />
  <logger level="WARN" name="org.quartz" />
  <logger level="WARN" name="io.moquette"/>
  <logger level="ERROR" name="io.moquette.persistence.mapdb.MapDBSessionsStore"/>
  <logger level="ERROR" name="io.moquette.spi.impl.PersistentQueueMessageSender"/>

  <logger level="INFO" name="org.mycontroller.standalone" />
  <logger level="INFO" name="org.mycontroller.standalone.api" />
  <logger level="INFO" name="org.mycontroller.standalone.api.jaxrs" />
  <logger level="INFO" name="org.mycontroller.standalone.auth" />
  <logger level="INFO" name="org.mycontroller.standalone.backup" />
  <logger level="INFO" name="org.mycontroller.standalone.db" />
  <logger level="INFO" name="org.mycontroller.standalone.db.dao" />
  <logger level="INFO" name="org.mycontroller.standalone.db.migration" />
  <logger level="INFO" name="org.mycontroller.standalone.email" />
  <logger level="INFO" name="org.mycontroller.standalone.fwpayload" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.ethernet" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.mqtt" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.phantio" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.philipshue" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.rest" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.serial" />
  <logger level="INFO" name="org.mycontroller.standalone.gateway.wunderground" />
  <logger level="INFO" name="org.mycontroller.standalone.group" />
  <logger level="INFO" name="org.mycontroller.standalone.jobs" />
  <logger level="INFO" name="org.mycontroller.standalone.loggers.LoggerMySql" />
  <logger level="INFO" name="org.mycontroller.standalone.message" />
  <logger level="INFO" name="org.mycontroller.standalone.metric" />
  <logger level="INFO" name="org.mycontroller.standalone.metric.jobs" />
  <logger level="INFO" name="org.mycontroller.standalone.mqttbroker" />
  <logger level="INFO" name="org.mycontroller.standalone.provider" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.mycontroller" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.mysensors" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.phantio" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.philipshue" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.rflink" />
  <logger level="INFO" name="org.mycontroller.standalone.provider.wunderground" />
  <logger level="INFO" name="org.mycontroller.standalone.restclient" />
  <logger level="INFO" name="org.mycontroller.standalone.rule" />
  <logger level="INFO" name="org.mycontroller.standalone.scheduler" />
  <logger level="INFO" name="org.mycontroller.standalone.scripts" />
  <logger level="INFO" name="org.mycontroller.standalone.settings" />
  <logger level="INFO" name="org.mycontroller.standalone.timer" />
  <logger level="INFO" name="org.mycontroller.standalone.uidtag" />

  <root level="WARN">
    <appender-ref ref="FILE" />
  </root>

  <logger name="RAW_MESSAGE_LOGGER" level="INFO" additivity="false">
    <appender-ref ref="GATEWAY_RAW_MESSAGE_APPENDER" />
  </logger>

</configuration>
