欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

springboot+mybatis如何屏蔽掉mybatis日志

 更新時間:2023年05月16日 09:21:33   作者:bourbon_zero  
這篇文章主要介紹了springboot+mybatis如何屏蔽掉mybatis日志問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

springboot+mybatis屏蔽掉mybatis日志

使用的是logback日志,屏蔽掉mybatis的debug日志,只需要在配置文件(指的是application.yaml)將

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

注釋即可

同理,需要改日志,將該句添加在配置文件即可

關(guān)閉mybatis日志問題

說明

在網(wǎng)上找了一大圈都沒有靠譜的答案,有時候項(xiàng)目中的日志打印太多,需要屏蔽部分日志打印

mybatis 日志的實(shí)現(xiàn)

原理:就是mybatis 的日志抽取了公共的方法,需要依賴項(xiàng)目中的日志實(shí)現(xiàn)類,來實(shí)現(xiàn)日志打印,在不配置的時候,mybatis會按照如下的順序去查找日志實(shí)現(xiàn)類

Mybatis內(nèi)置的日志工廠提供日志功能,具體的日志實(shí)現(xiàn)有以下幾種方式:

  • SLF4J
  • Apache Commons Logging
  • Log4j 2
  • Log4j
  • JDK logging

其實(shí)打開源碼還有一些其他實(shí)現(xiàn),但這幾個是大家接觸的最多的,如果找到日志實(shí)現(xiàn),在項(xiàng)目啟動的時候,mybatis 就會打印相關(guān)日志

關(guān)閉日志

springboot 環(huán)境中

在mybatis 自動找不到 日志實(shí)現(xiàn)類的時候,可以指定日志實(shí)現(xiàn)類

在springboot 項(xiàng)目中可以通過在配置文件中配置該屬性來指定 mybatis.configuration.log-impl

mybatis.configuration.log-impl=org.apache.ibatis.logging.nologging.NoLoggingImpl

這里配置的實(shí)現(xiàn)類,就是無處理,這樣就關(guān)閉了日志打印,或者換成

org.apache.ibatis.logging.stdout.StdOutImpl

這兩個mybatis 自帶的實(shí)現(xiàn)類,NoLoggingImpl 是啥也不做,StdOutImpl 是將日志輸出到控制臺

public class StdOutImpl implements Log {
? ? public StdOutImpl(String clazz) {
? ? }
? ? public boolean isDebugEnabled() {
? ? ? ? return true;
? ? }
? ? public boolean isTraceEnabled() {
? ? ? ? return true;
? ? }
? ? public void error(String s, Throwable e) {
? ? ? ? System.err.println(s);
? ? ? ? e.printStackTrace(System.err);
? ? }
? ? public void error(String s) {
? ? ? ? System.err.println(s);
? ? }
? ? public void debug(String s) {
? ? ? ? System.out.println(s);
? ? }
? ? public void trace(String s) {
? ? ? ? System.out.println(s);
? ? }
? ? public void warn(String s) {
? ? ? ? System.out.println(s);
? ? }
}

如果是其他環(huán)境

在mybatis.xml 文件中,指定相同的 log-iml 屬性 ,指定對應(yīng)的日志實(shí)現(xiàn)即可

總結(jié)

以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論