<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 1999-2023 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 status="WARN">
    <Properties>
        <Property name="userHome" value="${nacosClientProperty:user.home}"/>
        <Property name="logPath" value="${nacosClientProperty:JM.LOG.PATH:-${userHome}/logs}"/>
    </Properties>
    <Appenders>
        <RollingFile name="CONFIG_LOG_FILE" fileName="${logPath}/nacos/config.log"
            filePattern="${logPath}/nacos/config.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
            
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${nacosClientProperty:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
            
            <DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
                <Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-false}">
                    <IfFileName glob="config.log.*.*" />
                    <IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    
        <Async name="ASYNC_CONFIG" bufferSize="1024" blocking="false">
            <AppenderRef ref="CONFIG_LOG_FILE"/>
        </Async>
    
        <RollingFile name="REMOTE_LOG_FILE" fileName="${logPath}/nacos/remote.log"
            filePattern="${logPath}/nacos/remote.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
    
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${nacosClientProperty:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
    
            <DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
                <Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-false}">
                    <IfFileName glob="remote.log.*.*" />
                    <IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
                </Delete>
            </DefaultRolloverStrategy>
        </RollingFile>
    
        <Async name="ASYNC_REMOTE" bufferSize="1024" blocking="false">
            <AppenderRef ref="REMOTE_LOG_FILE"/>
        </Async>
        
        <RollingFile name="NAMING_LOG_FILE" fileName="${logPath}/nacos/naming.log"
            filePattern="${logPath}/nacos/naming.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
            
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${nacosClientProperty:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
            
            <DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
                <Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-false}">
                    <IfFileName glob="naming.log.*.*" />
                    <IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
                </Delete>
            </DefaultRolloverStrategy>

        </RollingFile>
    
        <Async name="ASYNC_NAMING" bufferSize="1024" blocking="false">
            <AppenderRef ref="NAMING_LOG_FILE"/>
        </Async>
        
        <RollingFile name="AI_LOG_FILE" fileName="${logPath}/nacos/naming.log"
            filePattern="${logPath}/nacos/ai.log.%d{yyyy-MM-dd}.%i">
            <PatternLayout>
                <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %p [%-5t:%c{2}] %m%n</Pattern>
            </PatternLayout>
            
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="${nacosClientProperty:JM.LOG.FILE.SIZE:-10MB}"/>
            </Policies>
            
            <DefaultRolloverStrategy max="${nacosClientProperty:JM.LOG.RETAIN.COUNT:-7}">
                <Delete basePath="${logPath}/nacos" maxDepth="1" testMode="${nacosClientProperty:JM.LOG.RETAIN.DURATION.OFF:-false}">
                    <IfFileName glob="ai.log.*.*" />
                    <IfLastModified age="${nacosClientProperty:JM.LOG.RETAIN.DURATION:-P180D}" />
                </Delete>
            </DefaultRolloverStrategy>
        
        </RollingFile>
        
        <Async name="ASYNC_AI" bufferSize="1024" blocking="false">
            <AppenderRef ref="AI_LOG_FILE"/>
        </Async>
    </Appenders>
    
    <Loggers>
        <Logger name="com.alibaba.nacos.client" level="${nacosClientProperty:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_CONFIG"/>
        </Logger>
    
        <Logger name="com.alibaba.nacos.common.remote.client" level="${nacosClientProperty:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_REMOTE"/>
        </Logger>
    
        <Logger name="com.alibaba.nacos.common.labels" level="${nacosClientProperty:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_REMOTE"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.shaded.io.grpc" level="${nacosClientProperty:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <appender-ref ref="ASYNC_REMOTE"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.client.config" level="${nacosClientProperty:com.alibaba.nacos.config.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_CONFIG"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.client.naming" level="${nacosClientProperty:com.alibaba.nacos.naming.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_NAMING"/>
        </Logger>
        
        <Logger name="com.alibaba.nacos.client.ai" level="${nacosClientProperty:com.alibaba.nacos.ai.log.level:-info}"
            additivity="false">
            <AppenderRef ref="ASYNC_AI"/>
        </Logger>
    </Loggers>
</Configuration>
