Spring boot uses logback as default logging provider for Slf4j. Ibatis internal log factory loads the SLF4j as the first choice logger. All you have to do is configure your spring boot logger to publish log messages for ibatis mapper.
Add the below lines in boot application properties.
logging.level.org.springframework=WARN
logging.level.com.spring.ibatis.UserMapper=DEBUG
logging.file=logs/spring-boot-logging.log
The second line is where you define the logging entry for ibatis mapper with DEBUG log level. com.spring.ibatis
is package and the UserMapper
is sample mapper.
The following logs will start to appear in the console and in the spring-boot-logging file. These are the log messages generated from saveUser
and findByName
method of ApplicationTest
class.
2016-12-19 22:07:06.358 INFO 7248 --- [main] com.spring.ibatis.ApplicationTest : Started ApplicationTest in 3.048 seconds (JVM running for 4.209)
2016-12-19 22:07:06.424 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.saveUser : ==> Preparing: insert into users(name) values(?)
2016-12-19 22:07:06.444 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.saveUser : ==> Parameters: ibatis(String)
2016-12-19 22:07:06.445 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.saveUser : <== Updates: 1
2016-12-19 22:07:06.457 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.findByName : ==> Preparing: select name from users WHERE name=?
2016-12-19 22:07:06.470 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.findByName : ==> Parameters: ibatis(String)
2016-12-19 22:07:06.504 DEBUG 7248 --- [main] com.spring.ibatis.UserMapper.findByName : <== Total: 1
You can of course configure any choice of logger you want. I can easily add an example for any other logger should you need.
You can find the complete code with Junit test cases at
https://github.com/saagar2000/ibatis
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…