logback配置模板

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <property name="app_name" value="optimus-h5" />
    <property name="root_dir" value="/opt/logs" />
    <contextName>${app_name}</contextName>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <Pattern>%d{HH:mm:ss.SSS} %-5level %logger{36}[%line] - %msg%n
            </Pattern>
        </layout>
    </appender>
    <appender name="ErrorAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${root_dir}/${app_name}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${root_dir}/${app_name}/%d{yyyy-MM-dd}-error.log
            </fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36}[%line] - %msg%n
            </pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter"><!-- 只打印错误日志 -->
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>
    <appender name="InfoAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${root_dir}/${app_name}/info.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${root_dir}/${app_name}/%d{yyyy-MM-dd}-info.log
            </fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36}[%line] - %msg%n
            </pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter"><!-- 打印info级别以上日志 -->
            <level>INFO</level>
        </filter>
    </appender>
    <appender name="FrameworkAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${root_dir}/${app_name}/framework.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${root_dir}/${app_name}/%d{yyyy-MM-dd}-framework.log
            </fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{36}[%line] - %msg%n
            </pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.ThresholdFilter"><!-- 打印info级别以上日志 -->
            <level>INFO</level>
        </filter>
    </appender>
    <appender name="SQLAppender"
        class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${root_dir}/${app_name}/sql.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <fileNamePattern>${root_dir}/${app_name}/%d{yyyy-MM-dd}-sql.log
            </fileNamePattern>
        </rollingPolicy>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %logger{50} - %msg%n
            </pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>DEBUG</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>
    <logger level="info" name="org.springframework">
        <appender-ref ref="FrameworkAppender" />
    </logger>
    <logger level="info" name="org.apache.cxf">
        <appender-ref ref="FrameworkAppender" />
    </logger>
    <logger level="info" name="org.mybatis">
        <appender-ref ref="FrameworkAppender" />
    </logger>
    <logger level="debug" name="com.netfinworks.optimus.mapper">
        <appender-ref ref="SQLAppender" />
    </logger>
    <logger level="info" name="com.netfinworks.optimus">
        <appender-ref ref="InfoAppender" />
        <appender-ref ref="ErrorAppender" />
    </logger>
    <logger level="error" name="org.apache">
        <appender-ref ref="ErrorAppender" />
    </logger>
    <root level="info">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>  




posted @ 2016-05-06 14:49  skyding  阅读(1237)  评论(0编辑  收藏  举报