提交修改
This commit is contained in:
parent
4ac4694878
commit
95373e78e0
@ -69,7 +69,7 @@ public class SQLBatchInsertLogInterceptor extends SqlParserHandler implements In
|
||||
Object parameterObject = boundSql.getParameterObject();
|
||||
Throwable throwable = new Throwable();
|
||||
String sqlCommandTypePre = mapperdId + " ";
|
||||
String peek0 = ServiceAop.peek();
|
||||
String peek0 ="";
|
||||
if (StringUtils.isNotBlank(peek0)) {
|
||||
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
|
||||
String classInfos[] = peek0.split(":");
|
||||
|
||||
@ -64,7 +64,7 @@ public class SQLInsertLogInterceptor extends SqlParserHandler implements Interce
|
||||
Object parameterObject = boundSql.getParameterObject();
|
||||
Throwable throwable = new Throwable();
|
||||
String sqlCommandTypePre = mapperdId + " ";
|
||||
String peek0 = ServiceAop.peek();
|
||||
String peek0 = "";
|
||||
if (StringUtils.isNotBlank(peek0)) {
|
||||
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
|
||||
String classInfos[] = peek0.split(":");
|
||||
|
||||
@ -1,137 +0,0 @@
|
||||
package com.heyu.api.data.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* 日志aop
|
||||
* Created by wutao on 2018/10/12.
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(2)
|
||||
@Slf4j
|
||||
public class ServiceAop {
|
||||
|
||||
|
||||
public final static ThreadLocal<ArrayStack> arrayStackThreadLocal = new ThreadLocal();
|
||||
|
||||
|
||||
@Pointcut(value = "( " +
|
||||
" execution(* com.heyu.api..*.*Impl.*(..)) " +
|
||||
" || execution(* com.heyu.api..*.*Controller.*(..)) " +
|
||||
" || execution(* com.heyu.api..*.*Bussiness.*(..)) " +
|
||||
" || execution(* com.heyu.api..*.*Handler.*(..)) " +
|
||||
" || execution(* com.heyu.api..*.*Strategy*.*(..)) " +
|
||||
" )")
|
||||
public void pointcut() {
|
||||
|
||||
}
|
||||
|
||||
@Around("pointcut()")
|
||||
public Object doAround(ProceedingJoinPoint point) throws Throwable {
|
||||
String no = ch.qos.logback.classic.Logger.inheritableThreadLocalNo.get();
|
||||
if (StringUtils.isBlank(no)) {
|
||||
try {
|
||||
return point.proceed();
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
Object result = null;
|
||||
Signature signature = point.getSignature();
|
||||
MethodSignature methodSignature = (MethodSignature) signature;
|
||||
Method method = methodSignature.getMethod();
|
||||
String allClassName = method.getDeclaringClass().getName(); // 全类名
|
||||
Throwable throwable = new Throwable();
|
||||
String lineNumber = getLineNumber(allClassName, method.getName(), throwable);
|
||||
String className = method.getDeclaringClass().getSimpleName();
|
||||
String methodName = method.getName();
|
||||
String key = lineNumber + "=>" + methodName + ":" + className;
|
||||
String oldNo = "";
|
||||
try {
|
||||
oldNo = ch.qos.logback.classic.Logger.inheritableThreadLocalNo.get();
|
||||
ch.qos.logback.classic.Logger.inheritableThreadLocalNo.set(oldNo + key);
|
||||
result = point.proceed();
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
throw e;
|
||||
} finally {
|
||||
ch.qos.logback.classic.Logger.inheritableThreadLocalNo.set(oldNo);
|
||||
pop();
|
||||
if(className.endsWith("Controller")){
|
||||
arrayStackThreadLocal.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String getLineNumber(String className, String methodName, Throwable throwable ) {
|
||||
String classInfo = className +":"+ methodName;
|
||||
try {
|
||||
if(className.endsWith("Controller")){
|
||||
return "";
|
||||
}
|
||||
|
||||
String peek = peek();
|
||||
if(StringUtils.isBlank(peek)){
|
||||
return "";
|
||||
}
|
||||
StackTraceElement[] elements =throwable.getStackTrace();
|
||||
for (StackTraceElement stackTraceElement : elements) {
|
||||
String c = stackTraceElement.getClassName();
|
||||
String mName = stackTraceElement.getMethodName();
|
||||
if(peek.equals(c +":"+ mName)){
|
||||
return ":"+stackTraceElement.getLineNumber();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("解析类信息异常", e);
|
||||
} finally {
|
||||
push(classInfo);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
public static void push(String classInfo ){
|
||||
ArrayStack arrayStack = arrayStackThreadLocal.get();
|
||||
if(arrayStack == null){
|
||||
arrayStack = new ArrayStack();
|
||||
}
|
||||
arrayStack.push( classInfo);
|
||||
arrayStackThreadLocal.set(arrayStack);
|
||||
}
|
||||
|
||||
public static String peek(){
|
||||
ArrayStack arrayStack = arrayStackThreadLocal.get();
|
||||
if(arrayStack == null){
|
||||
return null;
|
||||
}
|
||||
if(arrayStack.size() > 0 ){
|
||||
return (String) arrayStack.peek();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String pop(){
|
||||
ArrayStack arrayStack = arrayStackThreadLocal.get();
|
||||
if(arrayStack == null){
|
||||
return null;
|
||||
}
|
||||
if(arrayStack.size() > 0 ){
|
||||
return (String) arrayStack.pop();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -71,7 +71,7 @@ public class SqlLogInterceptor extends SqlParserHandler implements Interceptor {
|
||||
String mapperdId = getMapperId(mappedStatement);
|
||||
Throwable throwable = new Throwable();
|
||||
String sqlCommandTypePre = mapperdId + " ";
|
||||
String peek0 = ServiceAop.peek();
|
||||
String peek0 = "";
|
||||
if (StringUtils.isNotBlank(peek0)) {
|
||||
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
|
||||
String classInfos[] = peek0.split(":");
|
||||
|
||||
@ -18,12 +18,8 @@
|
||||
package com.heyu.api.data.config;
|
||||
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
import com.baomidou.mybatisplus.core.toolkit.PluginUtils;
|
||||
|
||||
import com.heyu.api.data.dto.ScopeData;
|
||||
import com.heyu.api.data.utils.DateUtils;
|
||||
import com.heyu.api.data.utils.EnvUtils;
|
||||
import com.heyu.api.data.utils.OrderUtil;
|
||||
import com.heyu.api.data.utils.ReflectionUtils;
|
||||
import com.lz.mybatis.plugins.interceptor.baomidou.SqlParserHandler;
|
||||
@ -42,15 +38,10 @@ import org.apache.ibatis.session.Configuration;
|
||||
import org.apache.ibatis.session.ResultHandler;
|
||||
import org.apache.ibatis.type.TypeHandlerRegistry;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.sql.Statement;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -82,7 +73,7 @@ public class SqlSelectLogInterceptor extends SqlParserHandler implements Interce
|
||||
String mapperdId = getMapperId(mappedStatement);
|
||||
Throwable throwable = new Throwable();
|
||||
String sqlCommandTypePre = mapperdId + " ";
|
||||
String peek0 = ServiceAop.peek();
|
||||
String peek0 = "";
|
||||
if (StringUtils.isNotBlank(peek0)) {
|
||||
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
|
||||
String classInfos[] = peek0.split(":");
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user