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

<Configuration status="WARN" monitorInterval="30">
    <Properties>
        <Property name="app.name">${sys:APP_NAME:-${env:APP_NAME:-application}}</Property>
        <Property name="log.path">${sys:LOG_PATH:-${env:LOG_PATH:-${sys:user.home}/logs}}</Property>
        <Property name="log.roll.pattern">${sys:LOG_ROLL_PATTERN:-${env:LOG_ROLL_PATTERN:-yyyy-MM-dd}}</Property>
        <Property name="LOG_PATTERN">%d{yyyy-MM-dd HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n</Property>
        <Property name="BYTEPLUS_TLS_ENDPOINT">${env:BYTEPLUS_TLS_ENDPOINT:-${env:VOLCENGINE_ENDPOINT:-}}</Property>
        <Property name="BYTEPLUS_TLS_ACCESS_KEY_ID">${env:BYTEPLUS_TLS_ACCESS_KEY_ID:-${env:VOLCENGINE_ACCESS_KEY_ID:-}}</Property>
        <Property name="BYTEPLUS_TLS_ACCESS_KEY_SECRET">${env:BYTEPLUS_TLS_ACCESS_KEY_SECRET:-${env:VOLCENGINE_ACCESS_KEY_SECRET:-}}</Property>
        <Property name="BYTEPLUS_TLS_REGION">${env:BYTEPLUS_TLS_REGION:-${env:VOLCENGINE_REGION:-ap-southeast-1}}</Property>
        <Property name="TLS_PROJECT_ID">${sys:byteplus.tls.projectId:-}</Property>
        <Property name="TLS_TOPIC_ID">${sys:byteplus.tls.topicId:-}</Property>
        <Property name="BYTEPLUS_TLS_BATCH_SIZE">${env:BYTEPLUS_TLS_BATCH_SIZE:-100}</Property>
        <Property name="BYTEPLUS_TLS_FLUSH_INTERVAL_SECONDS">${env:BYTEPLUS_TLS_FLUSH_INTERVAL_SECONDS:-5}</Property>
        <Property name="mybatis.sql.log.level">${sys:MYBATIS_SQL_LOG_LEVEL:-${env:MYBATIS_SQL_LOG_LEVEL:-INFO}}</Property>
    </Properties>

    <Appenders>
        <Console name="Console" target="SYSTEM_OUT">
            <PatternLayout pattern="${LOG_PATTERN}"/>
        </Console>

        <RollingFile name="RollingLogFile"
                     fileName="${log.path}/${app.name}.log"
                     filePattern="${log.path}/${app.name}/%d{${log.roll.pattern}}/%d{${log.roll.pattern}}-%i.log">
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <TimeBasedTriggeringPolicy/>
                <SizeBasedTriggeringPolicy size="200MB"/>
            </Policies>
            <DirectWriteRolloverStrategy maxFiles="10"/>
        </RollingFile>

        <Async name="AsyncRollingLogFile" bufferSize="262144">
            <AppenderRef ref="RollingLogFile"/>
        </Async>

        <BytePlusTLS name="BytePlusTLS"
                     endpoint="${BYTEPLUS_TLS_ENDPOINT}"
                     accessKeyId="${BYTEPLUS_TLS_ACCESS_KEY_ID}"
                     accessKeySecret="${BYTEPLUS_TLS_ACCESS_KEY_SECRET}"
                     region="${BYTEPLUS_TLS_REGION}"
                     projectId="${TLS_PROJECT_ID}"
                     topicId="${TLS_TOPIC_ID}"
                     batchSize="${BYTEPLUS_TLS_BATCH_SIZE}"
                     flushIntervalSeconds="${BYTEPLUS_TLS_FLUSH_INTERVAL_SECONDS}">
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
        </BytePlusTLS>
    </Appenders>

    <Loggers>
        <Logger name="org.springframework" level="INFO" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="com.alibaba.nacos" level="INFO" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="com.volcengine" level="INFO" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="com.exchange.log.appender" level="INFO" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="org.apache.ibatis" level="${mybatis.sql.log.level}" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="org.apache.ibatis.logging.jdbc" level="${mybatis.sql.log.level}" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Logger>
        <Logger name="com.exchange" level="${mybatis.sql.log.level}" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
            <AppenderRef ref="BytePlusTLS"/>
        </Logger>
        <Logger name="com.spot" level="${mybatis.sql.log.level}" additivity="false">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
            <AppenderRef ref="BytePlusTLS"/>
        </Logger>
        <Root level="INFO">
            <AppenderRef ref="Console"/>
            <AppenderRef ref="AsyncRollingLogFile"/>
        </Root>
    </Loggers>
</Configuration>
