From 867a66983621dd6ebf3a2a24d7a5f2812ae7f8bb Mon Sep 17 00:00:00 2001
From: zhangli <123879394@qq.com>
Date: Sun, 13 Jul 2025 00:53:10 +0800
Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=87=E9=9D=A2?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
pom.xml | 7 ++
.../com/sczx/car/aspect/WebLogAspect.java | 97 +++++++++++++++++++
2 files changed, 104 insertions(+)
create mode 100644 src/main/java/com/sczx/car/aspect/WebLogAspect.java
diff --git a/pom.xml b/pom.xml
index 647c0ff..e9abfa8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -215,6 +215,13 @@
1.5.5.Final
provided
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.83
+
diff --git a/src/main/java/com/sczx/car/aspect/WebLogAspect.java b/src/main/java/com/sczx/car/aspect/WebLogAspect.java
new file mode 100644
index 0000000..002a4b1
--- /dev/null
+++ b/src/main/java/com/sczx/car/aspect/WebLogAspect.java
@@ -0,0 +1,97 @@
+package com.sczx.car.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