From 8414bac6b7baecc03a9490642303c58e30525079 Mon Sep 17 00:00:00 2001
From: zhangli <123879394@qq.com>
Date: Sun, 13 Jul 2025 00:32:50 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=87=E9=9D=A2=E6=89=93?=
=?UTF-8?q?=E5=8D=B0=E6=97=A5=E5=BF=97?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 8 ++
.../com/sczx/user/aspect/WebLogAspect.java | 97 +++++++++++++++++++
2 files changed, 105 insertions(+)
create mode 100644 src/main/java/com/sczx/user/aspect/WebLogAspect.java
diff --git a/pom.xml b/pom.xml
index 8b4d3d8..7d1cbd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -215,6 +215,14 @@
1.5.5.Final
provided
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.83
+
+
diff --git a/src/main/java/com/sczx/user/aspect/WebLogAspect.java b/src/main/java/com/sczx/user/aspect/WebLogAspect.java
new file mode 100644
index 0000000..1665f69
--- /dev/null
+++ b/src/main/java/com/sczx/user/aspect/WebLogAspect.java
@@ -0,0 +1,97 @@
+package com.sczx.user.aspect;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.JoinPoint;
+import org.aspectj.lang.annotation.*;
+import org.slf4j.MDC;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.UUID;
+
+/**
+ * @Author Huang Kai
+ * @Date 2023/1/18 17:01
+ * @Version 1.0
+ */
+@Aspect
+@Component
+@Slf4j
+public class WebLogAspect {
+
+
+
+ /** 以 controller 包下定义的所有请求为切入点 */
+ @Pointcut("execution(public * com.sczx.*.controller.*.*(..))")
+ public void webLog() {}
+
+ /**
+ * 在切点之前织入
+ * @param joinPoint
+ */
+ @Before("webLog()")
+ public void doBefore(JoinPoint joinPoint) {
+ String uid = UUID.randomUUID().toString();
+ MDC.put("requestId",uid.substring(24,36));
+ // 开始打印请求日志
+ ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = null;
+ if (attributes != null) {
+ request = attributes.getRequest();
+ }
+ // 打印请求相关参数
+ log.info("========================= Start =========================");
+ // 打印请求入参
+ try{
+ Object[] args = joinPoint.getArgs();
+ List