1. 程式人生 > 程式設計 >springboot logback調整mybatis日誌級別無效的解決

springboot logback調整mybatis日誌級別無效的解決

現象

在日誌配置檔案 logback-spring.xml 中,無論怎麼修改級別,mybatis 的 sql 日誌都會打印出來。

原因

在 application.yml 中配置了 mybatis 的自定義日誌類,如下:

mybatis:
 configuration:
  log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

點進去檢視原始碼,發現 debug 日誌級別始終為 true,所以怎麼配置都不生效

public boolean isDebugEnabled() {
  return true;
}

public boolean isTraceEnabled() {
  return true;
}

解決方法

遮蔽 application.yml 中配置的 mybatis 自定義日誌類,然後在 logback-spring.xml 配置檔案中,將 mapper(及 dao)包,配置為 info 級別。

<!-- 修改其他包的日誌輸出級別 -->
<logger name="com.xxx.xxx.mapper" level="INFO"/>

到此這篇關於springboot logback調整mybatis日誌級別無效的解決的文章就介紹到這了,更多相關springboot 調整日誌級別無效內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!