|
@@ -9,6 +9,7 @@ import com.simuwang.logging.Logging;
|
|
|
import com.simuwang.logging.LoggingService;
|
|
|
import com.simuwang.logging.SystemLog;
|
|
|
import jakarta.servlet.http.HttpServletRequest;
|
|
|
+import jakarta.servlet.http.HttpServletResponse;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
|
import org.aspectj.lang.annotation.Around;
|
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
@@ -16,6 +17,7 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.aop.support.AopUtils;
|
|
|
import org.springframework.core.annotation.Order;
|
|
|
+import org.springframework.http.HttpMethod;
|
|
|
import org.springframework.util.StopWatch;
|
|
|
|
|
|
import java.util.Objects;
|
|
@@ -45,8 +47,8 @@ public class LoggingAspect {
|
|
|
}
|
|
|
HttpServletRequest request = ServletUtils.getRequest();
|
|
|
Logging.Builder builder = Logging.builder().title(title).type(annotation.type().getValue()).method(request.getMethod())
|
|
|
- .requestUri(URLUtil.getPath(request.getRequestURI())).remoteAddr(ServletUtils.getIpAddr(request))
|
|
|
- .params(joinPoint.getArgs() == null ? Objects.toString(request.getParameterMap()) : JSONUtil.toJsonStr(joinPoint.getArgs()));
|
|
|
+ .requestUri(URLUtil.getPath(request.getRequestURI())).remoteAddr(ServletUtils.getIpAddr(request));
|
|
|
+ builder.params(this.getParams(request, joinPoint.getArgs()));
|
|
|
StopWatch watch = new StopWatch();
|
|
|
watch.start();
|
|
|
Object result;
|
|
@@ -71,4 +73,34 @@ public class LoggingAspect {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ private String getParams(HttpServletRequest request, Object[] args) {
|
|
|
+ if (args == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ boolean uploadRequest = isUploadRequest(request);
|
|
|
+ StringBuilder params;
|
|
|
+ if (request.getMethod().equalsIgnoreCase(HttpMethod.GET.name()) && !uploadRequest) {
|
|
|
+ params = new StringBuilder(Objects.toString(request.getParameterMap()));
|
|
|
+ } else if (uploadRequest) {
|
|
|
+ params = new StringBuilder();
|
|
|
+ for (Object arg : args) {
|
|
|
+ if (arg instanceof HttpServletRequest || arg instanceof HttpServletResponse) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ params.append(arg);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ params = new StringBuilder(JSONUtil.toJsonStr(args));
|
|
|
+ }
|
|
|
+ return params.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean isUploadRequest(HttpServletRequest request) {
|
|
|
+ String method = request.getMethod();
|
|
|
+ String contentType = request.getContentType();
|
|
|
+
|
|
|
+ return HttpMethod.POST.name().equalsIgnoreCase(method)
|
|
|
+ && contentType != null && contentType.startsWith("multipart/form-data");
|
|
|
+ }
|
|
|
}
|