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

    Copyright (C) 2003-2017 eXo Platform SAS.

    This is free software; you can redistribute it and/or modify it
    under the terms of the GNU Lesser General Public License as
    published by the Free Software Foundation; either version 3 of
    the License, or (at your option) any later version.

    This software is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this software; if not, write to the Free
    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    02110-1301 USA, or see the FSF site: http://www.fsf.org.

-->
<!--
Logback ${ch.qas.logback.version} configuration file.
For more details see : http://logback.qos.ch/manual/configuration.html
-->
<configuration scan="${EXO_DEV}" scanPeriod="30 seconds" debug="false">
  <!-- Enable JMX to configure logs -->
  <jmxConfigurator />
  <!-- Default pattern used for printing logs in files and on the console for systems that doesn't support a colorized output -->
  <property name="exo.logs.default.pattern" value="%date{ISO8601} | %-5level | %msg [%logger{40}&lt;%thread&gt;] %n%xEx" />
  <!-- Pattern used for console supporting ANSI colors -->
  <property name="exo.logs.colorized.pattern" value="%date{ISO8601} | %highlight(%-5level) | %msg %green([%logger{40}){}%cyan(&lt;%thread&gt;){}%green(]){} %n%xEx" />
  <!-- Logs are daily archived or whenever the file size reaches maxFileSize -->
  <property name="exo.logs.rolling.maxFileSize" value="100Mb" />
  <!-- Number of archives to keep -->
  <property name="exo.logs.rolling.maxHistory" value="60" />
  <!-- Allow to customize previous settings by defining these properties in ${exo.conf.dir}/exo.properties -->
  <define name="EXO_PROPERTIES_FILE_EXISTS" class="ch.qos.logback.core.property.FileExistsPropertyDefiner">
    <path>${exo.conf.dir}/exo.properties</path>
  </define>
  <if condition='property("EXO_PROPERTIES_FILE_EXISTS").equals("true")'>
    <then>
      <property file="${exo.conf.dir}/exo.properties" />
    </then>
  </if>
  <!--
  LevelChangePropagator propagates changes made to the level of any logback-classic logger onto the java.util.logging framework.
  Such propagation eliminates the performance impact of disabled log statements.
  -->
  <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator">
    <resetJUL>true</resetJUL>
  </contextListener>
  <!--
  Main logs file for platform
  -->
  <appender name="FILE_EXO_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${catalina.base}/logs/chat-server.log</file>
    <append>true</append>
    <encoder>
      <pattern>${exo.logs.default.pattern}</pattern>
      <outputPatternAsHeader>true</outputPatternAsHeader>
    </encoder>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
      <!-- daily rollover -->
      <fileNamePattern>${catalina.base}/logs/chat-server-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
      <!-- Max number of archives to keep -->
      <maxHistory>${exo.logs.rolling.maxHistory}</maxHistory>
      <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
        <!-- or whenever the file size reaches maxFileSize -->
        <maxFileSize>${exo.logs.rolling.maxFileSize}</maxFileSize>
      </timeBasedFileNamingAndTriggeringPolicy>
    </rollingPolicy>
  </appender>
  <appender name="ASYNC_EXO_LOG" class="ch.qos.logback.classic.AsyncAppender">
    <!-- Increase blocking queue capacity - 256 by default -->
    <queueSize>512</queueSize>
    <!-- Do not loose any event -->
    <discardingThreshold>0</discardingThreshold>
    <appender-ref ref="FILE_EXO_LOG" />
  </appender>
  <logger name="org.exoplatform" level="INFO" />
  <logger name="org.gatein" level="INFO" />
  <logger name="org.chromattic" level="INFO" />
  <logger name="jcr" level="INFO" />
  <logger name="exo.jcr" level="INFO" />
  <logger name="ws" level="INFO" />
  <logger name="XMLResolvingServiceImpl" level="INFO" />
  <logger name="TRAXTemplatesServiceImpl" level="INFO" />
  <logger name="org.apache.shindig" level="WARN" />
  <logger name="com.google.javascript.jscomp" level="WARN" />
  <logger name="org.apache.tomcat.util.digester.Digester" level="ERROR" />
  <logger name="org.apache.catalina.realm.JAASRealm" level="ERROR"/>
  <logger name="org.cometd.server.websocket" level="WARN" />
  <if condition='"true".equals(property("EXO_LOGS_DISPLAY_CONSOLE"))'>
    <then>
      <!-- This is activated by default on unix like systems -->
      <if condition='property("os.name").contains("Windows")'>
        <then>
          <!-- Colorization of logs isn't activated by default on Windows -->
          <!-- There are various issues with it like http://jira.qos.ch/browse/LOGBACK-762 -->
          <property name="exo.logs.colorized.console" value="${EXO_LOGS_COLORIZED_CONSOLE:-false}" />
          <!-- On Windows machines setting withJansi to true enables ANSI color code interpretation by the Jansi library. -->
          <property name="exo.logs.jansi.console" value="true" />
        </then>
        <else>
          <property name="exo.logs.colorized.console" value="${EXO_LOGS_COLORIZED_CONSOLE:-true}" />
          <property name="exo.logs.jansi.console" value="false" />
        </else>
      </if>
      <if condition='"true".equals(property("exo.logs.colorized.console"))'>
        <then>
          <!-- Colorized logs -->
          <property name="exo.logs.console.appender.pattern" value="${exo.logs.colorized.pattern}" />
        </then>
        <else>
          <property name="exo.logs.console.appender.pattern" value="${exo.logs.default.pattern}" />
        </else>
      </if>
      <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>${exo.logs.jansi.console:-false}</withJansi>
        <encoder>
          <pattern>${exo.logs.console.appender.pattern:-${exo.logs.default.pattern}}</pattern>
        </encoder>
      </appender>
      <root>
        <appender-ref ref="CONSOLE" />
      </root>
    </then>
  </if>
  <if condition='"true".equals(property("exo.jcr.session.tracking.active"))'>
    <then>
      <appender name="FILE_LEAK_DETECTOR_LOG" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${catalina.base}/logs/leak-detector.log</file>
        <append>true</append>
        <encoder>
          <pattern>${exo.logs.default.pattern}</pattern>
          <outputPatternAsHeader>true</outputPatternAsHeader>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
          <!-- daily rollover -->
          <fileNamePattern>${catalina.base}/logs/leak-detector-%d{yyyyMMdd}-%i.log.zip</fileNamePattern>
          <!-- Max number of archives to keep -->
          <maxHistory>${exo.logs.rolling.maxHistory}</maxHistory>
          <timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
            <!-- or whenever the file size reaches maxFileSize -->
            <maxFileSize>${exo.logs.rolling.maxFileSize}</maxFileSize>
          </timeBasedFileNamingAndTriggeringPolicy>
        </rollingPolicy>
      </appender>
      <appender name="ASYNC_LEAK_DETECTOR_LOG" class="ch.qos.logback.classic.AsyncAppender">
        <!-- Increase blocking queue capacity - 256 by default -->
        <queueSize>512</queueSize>
        <!-- Do not loose any event -->
        <discardingThreshold>0</discardingThreshold>
        <appender-ref ref="FILE_LEAK_DETECTOR_LOG" />
      </appender>
      <logger name="exo.jcr.component.core.SessionReference" level="ERROR" additivity="false">
        <appender-ref ref="ASYNC_LEAK_DETECTOR_LOG" />
      </logger>
      <if condition='"true".equals(property("EXO_LOGS_DISPLAY_CONSOLE"))'>
        <then>
          <logger name="exo.jcr.component.core.SessionReference">
            <appender-ref ref="CONSOLE" />
          </logger>
        </then>
      </if>
    </then>
  </if>
  <root level="INFO">
    <appender-ref ref="ASYNC_EXO_LOG" />
  </root>
</configuration>
