mybatis用logback日志不显示sql的解决方法

1.mybatis-config.xml的设定

关于logimpl的设定值还不支持logback,如果用SLF4J是不好用的。

这是官方文档的描述,见下图

 
mybatis用logback日志不显示sql的解决办法
 

设定改为STDOUT_LOGGING是可以显示sql的

	<settings>
		<setting name="logImpl" value="STDOUT_LOGGING" />
	</settings>

 

2.原因是:

mybatis源代码BaseExceutor.java

  protected Connection getConnection(Log statementLog) throws SQLException {
    Connection connection = transaction.getConnection();
    if (statementLog.isDebugEnabled()) {
      return ConnectionLogger.newInstance(connection, statementLog);
    } else {
      return connection;
    }
  }

 如果设定了

STDOUT_LOGGING

  实现类是StdOutImpl.java

  public boolean isDebugEnabled() {
    return true;
  }

 debug就开启了,log就可以打印sql了

 

3.logback.xml的设定


相关文章:

  • 2021-11-19
  • 2021-09-01
  • 2022-01-26
  • 2021-09-14
  • 2022-12-23
  • 2022-03-04
猜你喜欢
  • 2022-12-23
  • 2021-12-15
  • 2022-01-18
  • 2022-12-23
  • 2021-06-17
  • 2021-07-15
相关资源
相似解决方案