Commit 77471e09 authored by yanzg's avatar yanzg

接口文档的支持

parent 67b01f41
...@@ -33,8 +33,8 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -33,8 +33,8 @@ public class BaseRequestAspect implements ThreadNext.Next {
@Value("${spring.application.name}") @Value("${spring.application.name}")
protected String applicationName; protected String applicationName;
@Value("${yzg.logCommon:true}") @Value("${yzg.logCommon:false}")
protected boolean logCommon = true; protected boolean logCommon;
@Value("${yzg.logAll:false}") @Value("${yzg.logAll:false}")
protected boolean logAll = false; protected boolean logAll = false;
...@@ -164,9 +164,11 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -164,9 +164,11 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected long requestLog(String tag, ProceedingJoinPoint joinPoint) { protected long requestLog(String tag, ProceedingJoinPoint joinPoint) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
try { try {
String name = joinPoint.getSignature().getName(); if (logCommon) {
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s", String name = joinPoint.getSignature().getName();
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs())))); Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
}
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
} }
...@@ -182,7 +184,7 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -182,7 +184,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
* @param resultEx * @param resultEx
* @param start * @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 { try {
String name = joinPoint.getSignature().getName(); String name = joinPoint.getSignature().getName();
if (StringHelper.isEmpty(url)) { if (StringHelper.isEmpty(url)) {
...@@ -214,14 +216,13 @@ public class BaseRequestAspect implements ThreadNext.Next { ...@@ -214,14 +216,13 @@ public class BaseRequestAspect implements ThreadNext.Next {
} }
// 正常请求不记录 // 正常请求不记录
if (!logAll boolean error = resultEx != null || responseResult == null || ResultConstants.SUCCESS.equals(responseResult.getCode());
&& responseResult != null boolean logFlag = (logAll && save) || error;
&& responseResult.getCode() == ResultConstants.SUCCESS) { if (logFlag) {
return; 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) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
......
...@@ -9,6 +9,7 @@ import org.aspectj.lang.ProceedingJoinPoint; ...@@ -9,6 +9,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -22,6 +23,10 @@ public class FeignAspect extends BaseRequestAspect { ...@@ -22,6 +23,10 @@ public class FeignAspect extends BaseRequestAspect {
private static final String TAG = FeignAspect.class.getSimpleName(); private static final String TAG = FeignAspect.class.getSimpleName();
@Value("${yzg.logFeign:false}")
private boolean logFeign;
/** /**
* AOP的表达式 * AOP的表达式
*/ */
...@@ -62,7 +67,7 @@ public class FeignAspect extends BaseRequestAspect { ...@@ -62,7 +67,7 @@ public class FeignAspect extends BaseRequestAspect {
ex = e; ex = e;
throw e; throw e;
} finally { } 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; ...@@ -6,6 +6,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
...@@ -20,6 +21,9 @@ public class MqAspect extends BaseRequestAspect { ...@@ -20,6 +21,9 @@ public class MqAspect extends BaseRequestAspect {
private static final String TAG = MqAspect.class.getSimpleName(); private static final String TAG = MqAspect.class.getSimpleName();
@Value("${yzg.logMq:false}")
private boolean logMq;
/** /**
* exec aop point aspect * exec aop point aspect
*/ */
...@@ -48,7 +52,9 @@ public class MqAspect extends BaseRequestAspect { ...@@ -48,7 +52,9 @@ public class MqAspect extends BaseRequestAspect {
ex = e; ex = e;
throw e; throw e;
} finally { } 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 { ...@@ -36,6 +36,9 @@ public class WebAspect extends BaseRequestAspect {
@Autowired @Autowired
private TokenServiceCall tokenServiceCall; private TokenServiceCall tokenServiceCall;
@Value("${yzg.logWeb:false}")
private boolean logWeb;
@Value("${yzg.gateway:^.*gateway.*$}") @Value("${yzg.gateway:^.*gateway.*$}")
private String gateWay; private String gateWay;
...@@ -85,7 +88,7 @@ public class WebAspect extends BaseRequestAspect { ...@@ -85,7 +88,7 @@ public class WebAspect extends BaseRequestAspect {
tokenFinish(flag); tokenFinish(flag);
TokenHelper.remove(); 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