logback打印mybatis sql日志

近期在项目中调试sql,发现现有的配置 使用logback 无法打印出sql语句,原配置如下(修改为debug也不好使):

<!--jdbc -->
<logger name="java.sql.Connection" level="ERROR" />
<logger name="java.sql.PreparedStatement" level="ERROR" />
<logger name="org.apache.zookeeper" level="ERROR" />

经过资料查找与测试,什么在mybatis的配置文件增加<setting name="logPrefix"/> <setting name="logImpl"/> 统统不好使。

后来测试在logback.xml 中增加如下配置,打开Debug日志输出。 其中name="com.x.x.dao.XxxDao"  为mybatis DAO接口包路径

<logger name="com.x.x.dao.XxxDao" level="DEBUG" />

结果输出如下,  Preparing 为原sql, Parameters 为可变参数:

==> Preparing: select order_id, order_code, org_remark, add_payment, activity_id, evaluate_score FROM tc_order WHERE 1=1 and category =? and order_status = ? and start_date <=? and third_order_id = ?
2017-06-07 14:30:02,679 [executor-1] DEBUG com.xx.xx.dop2c.order.ext.TcOrderExtDao.queryForQueue - 47 - ==> Parameters: 253(Long), 30(Integer), 2017-06-07 14:30:02(String), 0(String)






原文地址:https://www.cnblogs.com/blacksonny/p/6956949.html