1. 程式人生 > >Log4j的XML配置示例

Log4j的XML配置示例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "http://toolkit.alibaba-inc.com/dtd/log4j/log4j.dtd">
<log4j:configuration xmlns:log4j='http://jakarta.apache.org/log4j/'
                     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                     xsi:schemaLocation="
http://jakarta.apache.org/log4j/ ">
    <appender name="consoleAppender" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="[%d{yyyy-MM-dd HH:mm:ss.SSS}]-[%c]-[%t] %x - %m%n"/>
        </layout>
    </appender>

    <!-- Mybatis and SQL -->
    <logger name="org.apache.ibatis" additivity="true">
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <logger name="org.mybatis.spring" additivity="true">
        <level value="ERROR"/>
        <appender-ref ref="consoleAppender"/>
    </logger>
    <logger name="java.sql" additivity="true">
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <logger name="java.sql.Connection" additivity="true">
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <logger name="java.sql.Statement" additivity="true">
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <logger name="java.sql.PreparedStatement" additivity="true">
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <!-- Spring -->
    <logger name="org.springframework" additivity="true">
        <level value="ERROR"/>
        <appender-ref ref="consoleAppender"/>
    </logger>

    <!-- ActiveMQ -->
    <logger name="org.apache.activemq" additivity="true">
        <level value="ERROR"/>
        <appender-ref ref="consoleAppender"/>
    </logger>
    <!-- ===================================================================== -->
    <!--  根日誌記錄器                                                          -->
    <!-- ===================================================================== -->
    <root>
        <level value="DEBUG"/>
        <appender-ref ref="consoleAppender"/>
    </root>
</log4j:configuration>