Commit 77471e09 authored by yanzg's avatar yanzg

接口文档的支持

parent 67b01f41
......@@ -33,8 +33,8 @@ public class BaseRequestAspect implements ThreadNext.Next {
@Value("${spring.application.name}")
protected String applicationName;
@Value("${yzg.logCommon:true}")
protected boolean logCommon = true;
@Value("${yzg.logCommon:false}")
protected boolean logCommon;
@Value("${yzg.logAll:false}")
protected boolean logAll = false;
......@@ -164,9 +164,11 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected long requestLog(String tag, ProceedingJoinPoint joinPoint) {
long start = System.currentTimeMillis();
try {
String name = joinPoint.getSignature().getName();
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
if (logCommon) {
String name = joinPoint.getSignature().getName();
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
}
} catch (Exception ex) {
ex.printStackTrace();
}
......@@ -182,7 +184,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
* @param resultEx
* @param start
*/
protected void responseLog(boolean clear, String tag, String url, ProceedingJoinPoint joinPoint, long start, Object result, Exception resultEx) {
protected void responseLog(boolean save, boolean clear, String tag, String url, ProceedingJoinPoint joinPoint, long start, Object result, Exception resultEx) {
try {
String name = joinPoint.getSignature().getName();
if (StringHelper.isEmpty(url)) {
......@@ -214,14 +216,13 @@ public class BaseRequestAspect implements ThreadNext.Next {
}
// 正常请求不记录
if (!logAll
&& responseResult != null
&& responseResult.getCode() == ResultConstants.SUCCESS) {
return;
boolean error = resultEx != null || responseResult == null || ResultConstants.SUCCESS.equals(responseResult.getCode());
boolean logFlag = (logAll && save) || error;
if (logFlag) {
LogVo logVo = initLogInterVo(url, joinPoint, responseResult);
logVo.setUseTime((int) time);
addLog(logVo);
}
LogVo logVo = initLogInterVo(url, joinPoint, responseResult);
logVo.setUseTime((int) time);
addLog(logVo);
} catch (Exception e) {
e.printStackTrace();
} finally {
......
......@@ -9,6 +9,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
......@@ -22,6 +23,10 @@ public class FeignAspect extends BaseRequestAspect {
private static final String TAG = FeignAspect.class.getSimpleName();
@Value("${yzg.logFeign:false}")
private boolean logFeign;
/**
* AOP的表达式
*/
......@@ -62,7 +67,7 @@ public class FeignAspect extends BaseRequestAspect {
ex = e;
throw e;
} finally {
responseLog(clear, TAG, StringHelper.EMPTY, joinPoint, start, result, ex);
responseLog(logFeign, clear, TAG, StringHelper.EMPTY, joinPoint, start, result, ex);
}
}
......
......@@ -6,6 +6,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
/**
......@@ -20,6 +21,9 @@ public class MqAspect extends BaseRequestAspect {
private static final String TAG = MqAspect.class.getSimpleName();
@Value("${yzg.logMq:false}")
private boolean logMq;
/**
* exec aop point aspect
*/
......@@ -48,7 +52,9 @@ public class MqAspect extends BaseRequestAspect {
ex = e;
throw e;
} finally {
responseLog(clear, TAG, StringHelper.EMPTY, joinPoint, start, result, ex);
if (logMq || ex != null) {
responseLog(logMq, clear, TAG, StringHelper.EMPTY, joinPoint, start, result, ex);
}
}
}
......
......@@ -36,6 +36,9 @@ public class WebAspect extends BaseRequestAspect {
@Autowired
private TokenServiceCall tokenServiceCall;
@Value("${yzg.logWeb:false}")
private boolean logWeb;
@Value("${yzg.gateway:^.*gateway.*$}")
private String gateWay;
......@@ -85,7 +88,7 @@ public class WebAspect extends BaseRequestAspect {
tokenFinish(flag);
TokenHelper.remove();
}
responseLog(clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex);
responseLog(logWeb, clear, TAG, HttpAspectUtil.getHttpRequestUrl(), joinPoint, start, result, ex);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment