提交 aefdf8e8 编写于 作者: lakernote's avatar lakernote

Logback异常堆栈剔除一些不关心的类

上级 e383c3f2
......@@ -6,9 +6,9 @@ import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerIntercept
import com.laker.admin.framework.ext.mybatis.PerformanceInterceptor;
import com.laker.admin.framework.ext.mybatis.datapermission.LakerDataPermissionV2Interceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
/**
* @author laker
......@@ -52,13 +52,13 @@ public class MybatisConfig {
* @return
*/
@Bean
@Profile("test")
@ConditionalOnProperty(value = "javamelody.enabled", havingValue = "false")
public PerformanceInterceptor performanceInterceptor() {
PerformanceInterceptor interceptor = new PerformanceInterceptor();
// sql美化打印
interceptor.setFormat(true);
// 设置SQL超时时间
interceptor.setMaxTime(1000L);
interceptor.setMaxTime(100L);
// 写入日志
interceptor.setWriteInLog(true);
return interceptor;
......
......@@ -16,6 +16,8 @@
package com.laker.admin.framework.ext.mybatis;
import com.baomidou.mybatisplus.core.toolkit.*;
import com.laker.admin.framework.aop.trace.SpanType;
import com.laker.admin.framework.aop.trace.TraceContext;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
......@@ -149,32 +151,36 @@ public class PerformanceInterceptor implements Interceptor {
if (index > 0) {
originalSql = originalSql.substring(index);
}
// 计算执行 SQL 耗时
long start = SystemClock.now();
Object result = invocation.proceed();
long timing = SystemClock.now() - start;
// 格式化 SQL 打印执行结果
Object target = PluginUtils.realTarget(invocation.getTarget());
MetaObject metaObject = SystemMetaObject.forObject(target);
MappedStatement ms = (MappedStatement) metaObject.getValue("delegate.mappedStatement");
StringBuilder formatSql = new StringBuilder()
.append(" Time:").append(timing)
.append(" ms - ID:").append(ms.getId())
.append(StringPool.NEWLINE).append("Execute SQL:")
.append(SQL_FORMATTER.format(originalSql)).append(StringPool.NEWLINE);
// 计算执行 SQL 耗时
long start = SystemClock.now();
String mapperId = ms.getId();
TraceContext.addSpan(mapperId, SpanType.Mapper);
Object result = null;
try {
result = invocation.proceed();
} catch (Exception e) {
throw e;
} finally {
TraceContext.stopSpan(this.getMaxTime() >= 1 ? this.getMaxTime() : 100);
long timing = SystemClock.now() - start;
// 格式化 SQL 打印执行结果
StringBuilder formatSql = new StringBuilder()
.append(" Time:").append(timing)
.append(" ms - ID:").append(mapperId)
.append(StringPool.NEWLINE).append("Execute SQL:")
.append(SQL_FORMATTER.format(originalSql)).append(StringPool.NEWLINE);
if (this.isWriteInLog()) {
if (this.getMaxTime() >= 1 && timing > this.getMaxTime()) {
log.error(formatSql.toString());
} else {
log.info(formatSql.toString());
if (this.isWriteInLog()) {
if (this.getMaxTime() >= 1 && timing > this.getMaxTime()) {
log.error(formatSql.toString());
} else {
log.warn("Execute {}ms,Mapper:{}", timing, mapperId);
}
}
} else {
System.err.println(formatSql.toString());
Assert.isFalse(this.getMaxTime() >= 1 && timing > this.getMaxTime(),
" The SQL execution time is too large, please optimize ! ");
}
return result;
}
......
......@@ -58,7 +58,7 @@ knife4j:
# 是否生产环境 屏蔽所有资源接口,一般这个用于生产环境 屏蔽资源,与上面二选一
# production: true
javamelody:
enabled: true
enabled: false
# sa-token配置
sa-token:
# token名称 (同时也是cookie名称)
......
......@@ -75,7 +75,7 @@
<!---->
<logger name="org.snaker.engine" level="ERROR"/>
<!-- 不支持通配符 com.laker.admin.module.**.mapper-->
<logger name="com.laker.admin.module" level="DEBUG"/>
<logger name="com.laker.admin.module" level="INFO"/>
<!-- 日志输出级别 -->
<root level="INFO">
<appender-ref ref="DEFAULT"/>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册