<?xml version="1.0" encoding="UTF-8"?>
<!--monitorInterval：Log4j is able to automatically detect modifying the configuration file and reconfigure itself, setting the interval in seconds-->
<configuration monitorInterval="5">
    <!--Log levels and prioritization: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL -->

    <!--Variable configuration-->
    <Properties>
        <!-- Formatted output: %date is the date, %thread is the thread name, %-5level: the level is 5 characters wide from the left %msg: the log message, %n is the newline character-->
        <!-- %logger{36} means the logger name can be up to 36 characters long -->
        <property name="LOG_PATTERN"
                  value="%date{YYYY-MM-dd HH:mm:ss.SSS} [%X{traceId}] [%thread] %-5level %logger{36} - %msg%n"/>
        <!-- Define the path for log storage -->
        <property name="FILE_PATH" value="${sys:user.home}/bigmeta/logs"/>
        <property name="FILE_NAME" value="bigmeta"/>
    </Properties>

    <appenders>

        <console name="Console" target="SYSTEM_OUT">
            <!--Format of the output log-->
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/>
        </console>

        <!-- This will print out all the information at the level of info and below. Each time the size exceeds size, the log of this size will be automatically stored under the folder created by year-month and compressed as an archive.-->
        <RollingFile name="RollingFileInfo" fileName="${FILE_PATH}/${FILE_NAME}_info.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-info-%d{yyyy-MM-dd}_%i.log.gz">
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--The interval attribute is used to specify how often to scroll, the default is 1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <!-- If the DefaultRolloverStrategy property is not set, the default is up to 7 files in the same folder to start overwriting-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>

        <!-- This will print out all the information at the level of warn and below. Each time the size exceeds size, the log of this size will be automatically stored under the folder created by year-month and compressed as an archive.-->
        <RollingFile name="RollingFileWarn" fileName="${FILE_PATH}/${FILE_NAME}_warn.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-warn-%d{yyyy-MM-dd}_%i.log.gz">
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="warn" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--The interval attribute is used to specify how often to scroll, the default is 1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <!-- If the DefaultRolloverStrategy property is not set, the default is up to 7 files in the same folder to start overwriting-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>

        <!-- This will print out all the information at the level of error and below. Each time the size exceeds size, the log of this size will be automatically stored under the folder created by year-month and compressed as an archive.-->
        <RollingFile name="RollingFileError" fileName="${FILE_PATH}/${FILE_NAME}_error.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-error-%d{yyyy-MM-dd}_%i.log.gz">
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="error" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--The interval attribute is used to specify how often to scroll, the default is 1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <!-- If the DefaultRolloverStrategy property is not set, the default is up to 7 files in the same folder to start overwriting-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>


        <!-- 这个会打印出所有的info及以下级别的信息，每次大小超过size，则这size大小的日志会自动存入按年份-月份建立的文件夹下面并进行压缩，作为存档-->
        <RollingFile name="RollingFileRuleLineage" fileName="${FILE_PATH}/${FILE_NAME}_process_lineage.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-process-lineage-%d{yyyy-MM-dd}_%i.log.gz">
            <!--控制台只输出level及以上级别的信息（onMatch），其他的直接拒绝（onMismatch）-->
            <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--interval属性用来指定多久滚动一次，默认是1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <!-- DefaultRolloverStrategy属性如不设置，则默认为最多同一文件夹下7个文件开始覆盖-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>


        <RollingFile name="KafkaMessageContent" fileName="${FILE_PATH}/${FILE_NAME}_message.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-message-%d{yyyy-MM-dd}_%i.log.gz">
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--The interval attribute is used to specify how often to scroll, the default is 1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="100MB"/>
            </Policies>
            <!-- If the DefaultRolloverStrategy property is not set, the default is up to 7 files in the same folder to start overwriting-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>

        <RollingFile name="SPM-LOGGER-APPENDER" fileName="${FILE_PATH}/${FILE_NAME}_spm.log"
                     filePattern="${FILE_PATH}/${FILE_NAME}-spm-%d{yyyy-MM-dd}.log.gz">
            <!--The console only outputs the information of level and above (onMatch), and other direct rejections (onMismatch)-->
            <ThresholdFilter level="info" onMatch="ACCEPT" onMismatch="DENY"/>
            <PatternLayout pattern="${LOG_PATTERN}"/>
            <Policies>
                <!--The interval attribute is used to specify how often to scroll, the default is 1 hour-->
                <TimeBasedTriggeringPolicy interval="1"/>
                <SizeBasedTriggeringPolicy size="300MB"/>
            </Policies>
            <!-- If the DefaultRolloverStrategy property is not set, the default is up to 7 files in the same folder to start overwriting-->
            <DefaultRolloverStrategy max="15"/>
        </RollingFile>

    </appenders>

    <!--The Logger node is used to specify the form of the log separately, for example, to specify different log levels for the classes under the specified package.-->
    <!--Then define loggers, the appender will take effect only if the logger is defined and the appender is introduced-->
    <loggers>
        <AsyncLogger name="org.apache.kafka" level="warn" additivity="false">
            <AppenderRef ref="Console"/>
        </AsyncLogger>
        <AsyncLogger name="org.springframework.cloud.stream.binder.kafka" level="warn" additivity="false">
            <AppenderRef ref="Console"/>
        </AsyncLogger>

        <!--Filter out some useless DEBUG information of spring and mybatis-->
        <AsyncLogger name="org.mybatis" level="info" additivity="false">
            <AppenderRef ref="Console"/>
        </AsyncLogger>
        <!--Monitoring system information-->
        <!--If additivity is set to false, the child Logger will only output in its own appender, but not in the appender of the parent Logger.-->
        <AsyncLogger name="org.springframework" level="info" additivity="false">
            <AppenderRef ref="Console"/>
        </AsyncLogger>

        <AsyncLogger name="KafkaMessageContent" level="info" additivity="false">
            <AppenderRef ref="KafkaMessageContent"/>
            <AppenderRef ref="Console"/>
        </AsyncLogger>

        <AsyncLogger name="SPM-LOGGER" additivity="false" level="INFO">
            <AppenderRef ref="SPM-LOGGER-APPENDER" level="INFO" />
        </AsyncLogger>

        <AsyncRoot level="INFO">
            <appender-ref ref="Console"/>
            <appender-ref ref="RollingFileInfo"/>
            <appender-ref ref="RollingFileWarn"/>
            <appender-ref ref="RollingFileError"/>
            <appender-ref ref="KafkaMessageContent"/>
<!--            <appender-ref ref="SPM-LOGGER-APPENDER"/>-->
        </AsyncRoot>
    </loggers>

</configuration>
