一、mybatis日誌優先級java
SLF4Jsql
Apache Commons Loggingapache
Log4j 2mybatis
Log4japp
JDK logging測試
指定某種日誌(相應日誌實現必須存在,啓動時調用,未測試)spa
org.apache.ibatis.logging.LogFactory.useSlf4jLogging();日誌
org.apache.ibatis.logging.LogFactory.useLog4JLogging();xml
org.apache.ibatis.logging.LogFactory.useJdkLogging();blog
org.apache.ibatis.logging.LogFactory.useCommonsLogging();
org.apache.ibatis.logging.LogFactory.useStdOutLogging();
二、對於xml配置的sql語句輸出(只使用log4j,測試能夠使用)
<mapper namespace="sysBackTask">
<select id="selectSysBackTask" parameterType="int" resultType="SysBackTask" >
select * from sys_back_task where id = #{id}
</select>
</mapper>
配置爲:
log4j.logger.org.mybatis=DEBUG
log4j.logger.org.mybatis.common.jdbc.SimpleDataSource=DEBUG
log4j.logger.org.mybatis.common.jdbc.ScriptRunner=DEBUG
log4j.logger.sysBackTask=TRACE
log4j.logger.java.sql.Connection=DEBUG
log4j.logger.java.sql.Statement=DEBUG
log4j.logger.java.sql.PreparedStatement=DEBUG
注意log4j.logger.sysBackTask=TRACE,中sysBackTask爲相應的namespace
三、對於註解方式的sql語句(未測試)
package org.mybatis.example;將log4j.logger.sysBackTask=TRACE變爲log4j.logger.org.mybatis.example.BlogMapper=TRACE
或使用接口log4j.logger.org.mybatis.example=TRACE