<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 1999-2018 Alibaba Group Holding Ltd.
  ~
  ~ 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>

    <statusListener class="ch.qos.logback.core.status.NopStatusListener" />
    
    <springProperty scope="context" name="logPath" source="nacos.logs.path" defaultValue="${user.home}/nacos/logs"/>
    
    <property name="LOG_HOME" value="${logPath}"/>
    
    <include resource="org/springframework/boot/logging/logback/defaults.xml"/>
    
    <include resource="META-INF/logback/nacos-included.xml"/>
    <include optional="true" resource="META-INF/logback/config-included.xml"/>
    <include optional="true" resource="META-INF/logback/naming-included.xml"/>
    <include optional="true" resource="META-INF/logback/.xml"/>
    
    <logger name="ch.qos.logback" level="ERROR"/>
    
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>${CONSOLE_LOG_PATTERN}</pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="rootFile"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/nacos.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/nacos.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>50MB</maxFileSize>
            <maxHistory>15</maxHistory>
            <totalSizeCap>512MB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="core-auth"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/core-auth.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/core-auth.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="protocol-raft"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/protocol-raft.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/protocol-raft.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="remote-core"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/remote-core.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/remote-core.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="remote-digest"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/remote-digest.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/remote-digest.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="remote-push"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/remote-push.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/remote-push.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <!--TPS control -->
    <appender name="plugin-control-connection"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/plugin-control-connection.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/plugin-control-connection.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>2GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    <appender name="plugin-control-tps"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/plugin-control-tps.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/plugin-control-tps.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>2GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="plugin-control"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/plugin-control.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/plugin-control.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>14</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    
    <appender name="protocol-distro"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/protocol-distro.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/protocol-distro.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="nacos-cluster"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/nacos-cluster.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/nacos-cluster.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <appender name="alipay-jraft"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${LOG_HOME}/alipay-jraft.log</file>
        <append>true</append>
        <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
            <fileNamePattern>${LOG_HOME}/alipay-jraft.log.%d{yyyy-MM-dd}.%i</fileNamePattern>
            <maxFileSize>2GB</maxFileSize>
            <maxHistory>7</maxHistory>
            <totalSizeCap>7GB</totalSizeCap>
            <cleanHistoryOnStart>true</cleanHistoryOnStart>
        </rollingPolicy>
        <encoder>
            <Pattern>%date %level %msg%n%n</Pattern>
            <charset>UTF-8</charset>
        </encoder>
    </appender>
    
    <root level="INFO">
        <appender-ref ref="rootFile"/>
    </root>
    
    <logger name="com.alibaba.nacos.core.auth" additivity="false" level="DEBUG">
        <appender-ref ref="core-auth"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.remote" additivity="false" level="DEBUG">
        <appender-ref ref="remote-core"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.remote.push" additivity="false" level="DEBUG">
        <appender-ref ref="remote-push"/>
    </logger>
    
    <!-- TPS Control-->
    <logger name="com.alibaba.nacos.plugin.control" additivity="false" level="DEBUG">
        <appender-ref ref="plugin-control"/>
    </logger>
    <logger name="com.alibaba.nacos.plugin.control.tps" additivity="false" level="DEBUG">
        <appender-ref ref="plugin-control-tps"/>
    </logger>
    
    <logger name="com.alibaba.nacos.plugin.control.connection" additivity="false" level="DEBUG">
        <appender-ref ref="plugin-control-connection"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.remote.digest" additivity="false" level="DEBUG">
        <appender-ref ref="remote-digest"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.protocol.raft" additivity="false" level="DEBUG">
        <appender-ref ref="protocol-raft"/>
    </logger>
    
    <logger name="com.alipay.sofa.jraft" additivity="false" level="INFO">
        <appender-ref ref="alipay-jraft"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.protocol.distro" additivity="false" level="INFO">
        <appender-ref ref="protocol-distro"/>
    </logger>
    
    <logger name="com.alibaba.nacos.core.cluster" additivity="false" level="INFO">
        <appender-ref ref="nacos-cluster"/>
    </logger>
    
    <springProfile name="standalone">
        
        <logger name="org.springframework" level="INFO">
            <appender-ref ref="CONSOLE"/>
        </logger>
        
        <logger name="org.apache.catalina.startup.DigesterFactory" level="INFO">
            <appender-ref ref="CONSOLE"/>
        </logger>
        
        <logger name="org.apache.catalina.util.LifecycleBase" level="ERROR">
            <appender-ref ref="CONSOLE"/>
        </logger>
        
        <logger name="org.apache.coyote.http11.Http11NioProtocol" level="WARN">
            <appender-ref ref="CONSOLE"/>
        </logger>
        
        <logger name="org.apache.tomcat.util.net.NioSelectorPool" level="WARN">
            <appender-ref ref="CONSOLE"/>
        </logger>
    
    </springProfile>
    
    <logger name="com.alibaba.nacos.core.listener.StartingApplicationListener" level="INFO">
        <appender-ref ref="CONSOLE"/>
    </logger>
    
    <logger name="com.alibaba.nacos.common.notify.NotifyCenter" level="INFO">
        <appender-ref ref="CONSOLE"/>
    </logger>
    
    <logger name="com.alibaba.nacos.sys.file.WatchFileCenter" level="INFO">
        <appender-ref ref="CONSOLE"/>
    </logger>
    
    <logger name="com.alibaba.nacos.common.executor.ThreadPoolManager" level="INFO">
        <appender-ref ref="CONSOLE"/>
    </logger>
</configuration>
