Commit ce382c60 authored by yanzg's avatar yanzg

不记录系统日志

parent df1fdbd7
......@@ -87,5 +87,35 @@ public class ArrayHelper {
return list;
}
/**
* 将数组添加到列表中
*
* @param list
* @param from
* @param <T>
*/
public static final <T extends Object> void addList(List<T> list, T[]... from) {
for (T[] item : from) {
for (T sub : item) {
list.add(sub);
}
}
}
/**
* 将数组添加到列表中
*
* @param list
* @param from
* @param <T>
*/
public static final <T extends Object> void addList(List<T> list, List<T>... from) {
for (List<T> item : from) {
for (T sub : item) {
list.add(sub);
}
}
}
}
......@@ -2,6 +2,7 @@ package com.yanzuoguang.cloud.aop;
import com.rabbitmq.client.Channel;
import com.yanzuoguang.util.exception.ExceptionHelper;
import com.yanzuoguang.util.helper.ArrayHelper;
import com.yanzuoguang.util.helper.JsonHelper;
import com.yanzuoguang.util.helper.StringHelper;
import com.yanzuoguang.util.log.Log;
......@@ -22,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
......@@ -234,30 +236,34 @@ public class BaseRequestAspect {
String name = signature.getName();
FeignClient feignClient = (FeignClient) declaringType.getAnnotation(FeignClient.class);
if (feignClient != null && signature instanceof MethodSignature) {
MethodSignature methodSignature = (MethodSignature) signature;
Method targetMethod = methodSignature.getMethod();
// 类路径
RequestMapping[] classRequests = (RequestMapping[]) declaringType.getAnnotationsByType(RequestMapping.class);
PostMapping[] classPosts = (PostMapping[]) declaringType.getAnnotationsByType(PostMapping.class);
GetMapping[] classGets = (GetMapping[]) declaringType.getAnnotationsByType(GetMapping.class);
List<Annotation> annotation = new ArrayList<>();
ArrayHelper.addList(annotation, classRequests, classPosts, classGets);
String baseUrl = String.format("%s.%s", declaringType.getSimpleName(), name);
if (!annotation.isEmpty() && signature instanceof MethodSignature) {
MethodSignature methodSignature = (MethodSignature) signature;
Method targetMethod = methodSignature.getMethod();
// 方法路径
RequestMapping[] requests = targetMethod.getAnnotationsByType(RequestMapping.class);
PostMapping[] posts = targetMethod.getAnnotationsByType(PostMapping.class);
GetMapping[] gets = targetMethod.getAnnotationsByType(GetMapping.class);
url = getFeignUrl(feignClient, classRequests, classPosts, classGets, requests, posts, gets);
url = getFeignOrRequestUrl(feignClient, classRequests, classPosts, classGets, requests, posts, gets);
} else {
Message message = getMessage(joinPoint.getArgs());
if (message != null) {
url = message.getMessageProperties().getConsumerQueue();
}
}
if (StringHelper.isEmpty(url)) {
url = String.format("%s.%s", declaringType.getSimpleName(), name);
return baseUrl;
}
return url;
return String.format("%s:%s", baseUrl, url);
}
/**
......@@ -272,11 +278,13 @@ public class BaseRequestAspect {
* @param gets
* @return
*/
private String getFeignUrl(FeignClient feignClient,
private String getFeignOrRequestUrl(FeignClient feignClient,
RequestMapping[] classRequests, PostMapping[] classPosts, GetMapping[] classGets,
RequestMapping[] requests, PostMapping[] posts, GetMapping[] gets) {
StringBuilder sb = new StringBuilder();
if (feignClient != null) {
sb.append(feignClient.value());
}
if (classRequests != null) {
for (RequestMapping item : classRequests) {
sb.append(item.value()[0]);
......
......@@ -73,7 +73,7 @@ public class WebAspect extends BaseRequestAspect {
LogVo log = null;
boolean clear = requestLogInit();
long start = System.currentTimeMillis();
String url = HttpAspectUtil.getHttpRequestUrl();
String url = getMethodUrl(joinPoint);
if (clear) {
log = startLog(TAG, url, getRequestBody(joinPoint));
clear = clear && log != null;
......
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