Commit c27c1a6b authored by yanzg's avatar yanzg

Merge remote-tracking branch 'origin/master'

parents ef72d0bc efe3f265
......@@ -5,6 +5,7 @@ import com.yanzuoguang.util.helper.StringHelper;
/**
* 日志处理默认处理函数
*
* @author 颜佐光
*/
public class LogDefault implements RunnableLog {
......@@ -35,9 +36,7 @@ public class LogDefault implements RunnableLog {
info.getMessage()
));
if (info.getException() != null) {
sb.append(System.lineSeparator());
sb.append(info.getException().getClass().getName());
sb.append(System.lineSeparator());
sb.append(info.getException().getMessage());
}
......
package com.yanzuoguang.cloud.aop;
import com.alibaba.fastjson.JSON;
import com.yanzuoguang.cloud.CloudContans;
import com.yanzuoguang.util.cache.MemoryCache;
import com.yanzuoguang.util.contants.ResultConstants;
import com.yanzuoguang.util.exception.ExceptionHelper;
......@@ -91,17 +90,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
logInterVo.setLogSources(applicationName);
//请求URL
logInterVo.setInterUrl(url);
List<Object> para = new ArrayList<>();
for (Object item : joinPoint.getArgs()) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
Object paraTo = getFirstDataParameter(joinPoint.getArgs());
//请求参数
logInterVo.setContent(JSON.toJSONString(paraTo));
//返回参数
......@@ -110,6 +99,37 @@ public class BaseRequestAspect implements ThreadNext.Next {
return logInterVo;
}
/**
* 获取请求的参数
*
* @param args
* @return
*/
protected Object getFirstDataParameter(Object[] args) {
List<Object> para = getDataParameters(args);
Object paraTo = para;
if (para.size() == 1) {
paraTo = para.get(0);
}
return paraTo;
}
/**
* 获取数据参数
* @param args
* @return
*/
protected List<Object> getDataParameters(Object[] args) {
List<Object> para = new ArrayList<>();
for (Object item : args) {
if (item instanceof HttpServlet || item instanceof HttpServletResponse || item instanceof HttpServletRequest) {
continue;
}
para.add(item);
}
return para;
}
/**
* 获取JSON,当Json过长时,截断
*
......@@ -147,7 +167,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
try {
String name = joinPoint.getSignature().getName();
Log.info(joinPoint.getSignature().getDeclaringType(), " %s [ %s ] request: %s",
tag, name, this.getMaxString(JsonHelper.serialize(joinPoint.getArgs())));
tag, name, this.getMaxString(JsonHelper.serialize(getFirstDataParameter(joinPoint.getArgs()))));
} catch (Exception ex) {
ex.printStackTrace();
}
......
......@@ -16,10 +16,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
/**
* LogsAspect(接口请求日志切面)
......@@ -148,9 +147,8 @@ public class WebAspect extends BaseRequestAspect {
* @throws Throwable
*/
private Object executeMethod(ProceedingJoinPoint joinPoint) throws Throwable {
boolean dataArgs = joinPoint.getArgs().length != 1
|| joinPoint.getArgs().length == 1 &&
(joinPoint.getArgs()[0] instanceof ServletResponse || joinPoint.getArgs()[0] instanceof ServletRequest);
List<Object> dataParas = this.getDataParameters(joinPoint.getArgs());
boolean dataArgs = dataParas.isEmpty();
Method method = getMethod(joinPoint);
boolean isUrl = false;
if (!StringHelper.isEmpty(reqUrl)) {
......@@ -166,7 +164,7 @@ public class WebAspect extends BaseRequestAspect {
return joinPoint.proceed();
} else {
// 获取请求编号
Object firstArgs = joinPoint.getArgs().length > 0 ? joinPoint.getArgs()[0] : null;
Object firstArgs = dataParas.size() > 0 ? dataParas.get(0) : null;
String reqId = StringHelper.md5(JsonHelper.serialize(firstArgs));
String reqFull = StringHelper.getId(reqId, HttpAspectUtil.getHttpRequestUrl());
RequestCacheResult req = cacheResult.get(reqFull, new RequestCacheResult(reqFull));
......
......@@ -21,7 +21,7 @@ public class TokenServiceCall implements TokenLoad {
private TokenService tokenService = null;
private int flagCount = 50;
private int flagCount = 3;
public TokenServiceCall() {
TokenHelper.setTokenLoad(this);
......
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