log4j2打印jdbcTemplate的sql以及參數


log4j2打印jdbcTemplate的sql以及參數

 

摘要: log4j2打印jdbcTemplate的sql以及參數。

 

在log4j2.xml加上這兩個logger即可:

<Logger name="org.springframework.jdbc.core" level="debug"/>
<Logger name="org.springframework.jdbc.core.StatementCreatorUtils" level="trace"/>

 

Logger解釋:

org.springframework.jdbc.core包下面的所有類,輸出debug級別的日志
其中,org.springframework.jdbc.core包下面的StatementCreatorUtils類,輸出trace級別的日志

 

打印的內容:

2018-10-10 15:52:16.458 DEBUG 45116 --- [e-nio-81-exec-5] o.s.j.c.JdbcTemplate                     : Executing prepared SQL statement [select * from t_user where username = ? and state = ?]
2018-10-10 15:52:16.459 TRACE 45116 --- [e-nio-81-exec-5] o.s.j.c.StatementCreatorUtils        : Setting SQL statement parameter value: column index 1, parameter value [admin], value class [java.lang.String], SQL type unknown
2018-10-10 15:52:16.459 TRACE 45116 --- [e-nio-81-exec-5] o.s.j.c.StatementCreatorUtils        : Setting SQL statement parameter value: column index 2, parameter value [1], value class [java.lang.Integer], SQL type unknown

 

打印內容解釋:

第一行是sql,值為select * from t_user where username = ? and state = ?
第二行是sql的第一個參數,值為admin,Java類型為String,sql類型為未知
第三行是sql的第二個參數,值為1,Java類型為Integer,sql類型為未知

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM