logback参考配置

 

logback配置

<?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>

  

posted @ 2018-09-26 10:39  吐槽村  阅读(382)  评论(0编辑  收藏  举报