MyBatis在log4j的输出配置,xml方式
<?xmlversion="1.0"encoding="UTF-8"?>
<!DOCTYPElog4j:configurationSYSTEM"log4j.dtd">
<log4j:configurationxmlns:log4j="http://jakarta.apache.org/log4j/"debug="true">
<!--输出日志到控制台-->
<appendername="CONSOLE"class="org.apache.log4j.ConsoleAppender">
<!--信息输出格式-->
<layoutclass="org.apache.log4j.PatternLayout">
<paramname="ConversionPattern"value="[%d{dd/MM/yyhh:mm:ss:sssz}]%5p%c{2}:%m%n"/>
</layout>
</appender>
<!--输出日志到文件-->
<appendername="FILE"class="org.apache.log4j.RollingFileAppender">
<!--文件路径-->
<paramname="file"value="${user.home}/yanglong-frameworkutil.log"/>
<paramname="append"value="true"/>
<!--文件大小-->
<paramname="maxFileSize"value="1MB"/>
<!--文件备份数量-->
<paramname="maxBackupIndex"value="1000"/>
<!--信息输出格式-->
<layoutclass="org.apache.log4j.PatternLayout">
<paramname="ConversionPattern"value="%d[%t]%-5p%C{6}(%F:%L)-%m%n"/>
</layout>
</appender>
<!--下面是打印mybatis语句的配置-->
<loggername="com.ibatis"additivity="true">
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
</logger>
<loggername="java.sql.Connection"additivity="true">
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
</logger>
<loggername="java.sql.Statement"additivity="true">
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
</logger>
<loggername="java.sql.PreparedStatement"additivity="true">
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
</logger>
<loggername="java.sql.ResultSet"additivity="true">
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
</logger>
<root>
<levelvalue="DEBUG"/>
<appender-refref="CONSOLE"/>
<appender-refref="FILE"/>
</root>
</log4j:configuration>