logback參考配置

 

logback配置html

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

<configuration>

    <contextName>share-manager</contextName>

    <property name="log.path" value="/logs/share-manager"/>
    <property name="COMMON_OUTPUT_PATTERN" value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{TRACE_ID}] [%p] %m%n %caller{0}" />

    <!-- 控制檯輸出 -->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder charset="UTF-8">
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
    </appender>

    <appender name="root" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/root.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/root.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>


    <!-- 異常日誌  暫時不須要 按照業務線來劃分日誌-->
    <appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <File>${log.path}/error.log</File>
        <append>true</append>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/error.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>


    <appender name="request" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/request.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/request.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="mq" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/mq.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/mq.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="slowSql" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/slow_sql.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/slow_sql.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="job" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/job.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/job.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>

    <appender name="shareManager" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${log.path}/share_manager.log</file>
        <append>true</append>
        <encoder>
            <pattern>${COMMON_OUTPUT_PATTERN}</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${log.path}/share_manager.log.%d{yyyy-MM-dd}</fileNamePattern>
            <maxHistory>15</maxHistory>
        </rollingPolicy>
    </appender>




    <!-- kafka日誌 -->
    <logger name="com.caocao.share.manager.kafka" level="INFO" additivity="false">
        <appender-ref ref="mq"/>
        <appender-ref ref="error"/>
    </logger>


    <logger name="com.alibaba.druid.filter.stat.StatFilter" level="INFO" additivity="false">
        <appender-ref ref="slowSql"/>
    </logger>

    <!-- 定時任務日誌 -->
    <logger name="com.caocao.share.manager.job" level="INFO" additivity="false">
        <appender-ref ref="job"/>
        <appender-ref ref="error"/>
    </logger>

    <!-- 請求日誌 -->
    <logger name="request" level="INFO" additivity="false">
        <appender-ref ref="request"/>
        <appender-ref ref="error"/>
    </logger>

    <!-- 關於service模塊下的全部日誌輸出配置 start -->
    <logger name="com.caocao.share.manager.serviceimpl" level="INFO" additivity="false">
        <appender-ref ref="shareManager"/>
        <appender-ref ref="error"/>
    </logger>

    <logger name="com.caocao.share.manager.api.impl" level="INFO" additivity="false">
        <appender-ref ref="shareManager"/>
        <appender-ref ref="error"/>
    </logger>

    <logger name="com.caocao.share.manager.handler" level="INFO" additivity="false">
        <appender-ref ref="shareManager"/>
        <appender-ref ref="error"/>
    </logger>

    <logger name="com.caocao.share.manager.common" level="INFO" additivity="false">
        <appender-ref ref="shareManager"/>
        <appender-ref ref="error"/>
    </logger>

    <!-- 關於service模塊下的全部日誌輸出配置 end -->


    <root level="INFO">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="root" />
    </root>

</configuration>
相關文章
相關標籤/搜索