xblueskyleng 2013-04-18 10:52
浏览 354
已采纳

mybatis3.2打印不出SQL语句

Spring3 struts2 mybatis3

JAR包:

[img]http://dl.iteye.com/upload/attachment/0083/3314/7a4ee1cd-c6be-37d5-9796-749f6d549049.png[/img]

[img]http://dl.iteye.com/upload/attachment/0083/3316/d0244429-f890-3f9d-b8f1-89b43063f434.png[/img]

Log4J配置:

[code="java"]
log4j.rootLogger=info, stdout, R
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n

log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=../logs/service.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.ibatis = debug
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug
log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug
log4j.logger.java.sql.Connection = debug
log4j.logger.java.sql.Statement = debug
log4j.logger.java.sql.PreparedStatement = debug,R
log4j.logger.java.sql.ResultSet =debug
[/code]
发现只有当 log4j.rootLogger=debug, stdout, R 时才打印SQL语句和结果出来。如果是info就不打印了。找了很久度娘和谷哥,不知道怎么回事。。

  • 写回答

10条回答

  • Dead_Knight 2013-04-19 10:32
    关注

    我把mybatis3.2的源码下载之后,把里面PooledDataSource类的log输出部分,换成log.warn之后,重新打jar包,放到项目中,日志级别改为info,如:
    [code="java"]
    log4j.rootLogger=info, stdout, R

    log4j.appender.stdout=org.apache.log4j.ConsoleAppender
    log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
    log4j.appender.stdout.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n

    log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
    log4j.appender.R.File=../logs/service.log
    log4j.appender.R.layout=org.apache.log4j.PatternLayout
    log4j.appender.R.layout.ConversionPattern=[service] %d - %c -%-4r [%t] %-5p %c %x - %m%n

    log4j.logger.com.ibatis = debug
    log4j.logger.com.ibatis.common.jdbc.SimpleDataSource = debug
    log4j.logger.com.ibatis.common.jdbc.ScriptRunner = debug
    log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate = debug
    log4j.logger.java.sql.Connection = debug
    log4j.logger.java.sql.Statement = debug
    log4j.logger.java.sql.PreparedStatement = debug
    log4j.logger.java.sql.ResultSet =debug
    [/code]

    此时,info级别能够输出warn级别的日志,我的日志显示如下:
    [code="java"]
    [service] 2013-04-19 10:30:57,982 - org.apache.ibatis.datasource.pooled.PooledDataSource -0 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
    [service] 2013-04-19 10:30:57,985 - org.apache.ibatis.datasource.pooled.PooledDataSource -3 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
    [service] 2013-04-19 10:30:57,986 - org.apache.ibatis.datasource.pooled.PooledDataSource -4 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
    [service] 2013-04-19 10:30:57,996 - org.apache.ibatis.datasource.pooled.PooledDataSource -14 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - PooledDataSource forcefully closed/removed all connections.
    [service] 2013-04-19 10:30:59,025 - org.apache.ibatis.datasource.pooled.PooledDataSource -1043 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Created connection 22323092.
    [service] 2013-04-19 10:30:59,076 - org.apache.ibatis.datasource.pooled.PooledDataSource -1094 [main] WARN org.apache.ibatis.datasource.pooled.PooledDataSource - Returned connection 22323092 to pool.
    [/code]

    很明显,这是显示warn的日志信息了。说明mybatis3只是打印了debug级别的日志。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(9条)

报告相同问题?

悬赏问题

  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料