logback-spring.xml 4.0 KB
<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="ture" scanPeriod="60 seconds" debug="false">

    <springProperty scope="context" name="appname" source="logback.appname"/>
    <springProperty scope="context" name="logdir" source="logback.logdir"/>
    <!--文件名-->
    <contextName>${appname}</contextName>

    <!--输出到控制面板-->
    <appender name="consoleLog1" class="ch.qos.logback.core.ConsoleAppender">
       <!-- layout输出方式输出-->
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
        </layout>
    </appender>
    <!--输出到控制面板-->
    <appender name="consoleLog" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <!--输出info级别日志-->
    <appender name="fileInfoLog" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <!--过滤 Error-->
            <level>ERROR</level>
            <!--匹配到就禁止-->
            <onMatch>DENY</onMatch>
            <!--没有匹配到就允许-->
            <onMismatch>ACCEPT</onMismatch>
        </filter>
        <!--<File>../logs</File>-->
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${logdir}/info.${appname}.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>100</maxHistory>
            <totalSizeCap>100MB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <charset>UTF-8</charset>
            <pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>
        </encoder>
    </appender>
    <!--输出Error级别日志-->
    <!--<appender name="fileErrorLog" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
        <!--<filter class="ch.qos.logback.classic.filter.LevelFilter">-->
            <!--&lt;!&ndash;过滤 Error &ndash;&gt;-->
            <!--<level>ERROR</level>-->
        <!--</filter>-->
        <!--&lt;!&ndash;<File>../logs</File>&ndash;&gt;-->
        <!--<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
            <!--<FileNamePattern>${logdir}/error.${appname}.%d{yyyy-MM-dd}.log</FileNamePattern>-->
            <!--<maxHistory>100</maxHistory>-->
             <!--<totalSizeCap>100MB</totalSizeCap>-->
        <!--</rollingPolicy>-->
        <!--<encoder>-->
            <!--<charset>UTF-8</charset>-->
            <!--<pattern>%d [%thread] %-5level %logger{36} %line - %msg%n</pattern>-->
        <!--</encoder>-->
    <!--</appender>-->
    <!--监控下列类的所有日志,定义输出级别-->
    <logger name="java.sql.PreparedStatement" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger>    
    <logger name="java.sql.Connection" level="DEBUG" additivity="false"> 
        <appender-ref ref="consoleLog"/>
    </logger>  
    <logger name="java.sql.Statement" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger>    
    <logger name="com.ibatis" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger>    
    <logger name="com.ibatis.common.jdbc.SimpleDataSource" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger>    
    <logger name="com.ibatis.common.jdbc.ScriptRunner" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger>    
    <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate" level="DEBUG" additivity="false">
        <appender-ref ref="consoleLog"/>
    </logger> 
    <!--输出-->
    <root level="INFO">
        <appender-ref ref="consoleLog"/>
        <!--<appender-ref ref="consoleLog"/>-->
        <appender-ref ref="fileInfoLog"/>
        <!--<appender-ref ref="fileErrorLog"/>-->
    </root>

</configuration>