问题:
想关闭某个包下的或者方法下的日志打印,定时任务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;
}
}
====
到这就完成了