mybatis-plus日志无法通过logging.level.包名关闭

问题
想关闭某个包下的或者方法下的日志打印,定时任务mybatis-plus SQL日志无法通过spring的配置项logging.level+包名关闭,因为mybatis-plus日志打印是他自己实现的
由于打印是系统调用,
数据量非常大是非常印象性能的

解决方案
实现Mybaits-Plus Log接口,自定义实现类,然后再配置中加入
在这里插入图片描述
在这里插入图片描述

/**

  • 自定义mybatis-plus日志实现类,用于控制异步线程中的sql日志打印

  • @author: Rain
    */
    public class MyStdOutImpl implements Log {

    public MyStdOutImpl(String clazz) {
    }

    @Override
    public boolean isDebugEnabled() {
    return true;
    }

    @Override
    public boolean isTraceEnabled() {
    return AirdropJob.stdOutFlag != null && AirdropJob.stdOutFlag.get().equals(Boolean.TRUE);
    }

    @Override
    public void error(String s, Throwable e) {
    System.out.println(s);

     e.printStackTrace(System.err);
    

    }

    @Override
    public void error(String s) {
    System.out.println(s);

    }

    @Override
    public void debug(String s) {
    System.out.println(s);
    }

    @Override
    public void trace(String s) {
    System.out.println(s);
    }

    @Override
    public void warn(String s) {
    System.out.println(s);
    }
    }

==================================================

添加一个注解

/**

  • 跳过该方法的日志打印,前提使用自定义的日志打印类
  • @author Rain
    */
    @Target(ElementType.METHOD)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface SkipSQLLog {
    }

==================================

编写切面

/**

  • @Description:

  • @Author Rain

  • @Version 1.0

  • @Tool: IntelliJ IDEA
    */
    @Aspect
    @Component
    //确保在AOP链条的最后,因为定时任务是使用异步线程池执行的,不加可能不行!!
    @Order(Integer.MIN_VALUE)
    public class SkipSqlAop {

    public static ThreadLocal stdOutFlag = new ThreadLocal();

    @Pointcut(“@annotation(com.mall.nft.app.annotation.SkipSQLLog)”)
    public void SkipSQLLog() {
    }

    @Around(value = “SkipSQLLog()”)
    public Object doSkipSQLLog(ProceedingJoinPoint joinPoint) {
    stdOutFlag.set(Boolean.FALSE);
    Object result = null;
    try {
    result = joinPoint.proceed(joinPoint.getArgs());
    } catch (Throwable throwable) {
    throwable.printStackTrace();
    } finally {
    stdOutFlag.set(Boolean.TRUE);
    }
    return result;
    }
    }

====
到这就完成了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值