To log SQL statements for particular mybatis mapper set DEBUG (TRACE to see query parameters and results) level for logger with fully qualified mapper name
这里的name值mapper接口的全限定名
<logger name="com.mycompany.myapp.mapper.MyMapper" level="DEBUG"/>
You can log all SQL statements from all mappers if they are in the same package like this
这里的name值mapper接口所在的包名
<logger name="com.mycompany.myapp.mapper" level="DEBUG"/>
日志的级别需要是DEBUG
原因:mybatis源代码BaseExceutor.java
protected Connection getConnection(Log statementLog) throws SQLException { Connection connection = transaction.getConnection(); if (statementLog.isDebugEnabled()) { return ConnectionLogger.newInstance(connection, statementLog, queryStack); } else { return connection; } }
refer:http://stackoverflow.com/questions/21718097/how-to-configure-logback-for-mybatis-to-print-my-sql