From ed838e62602c0a63a64ff4bd144a0d16cc9a7cf8 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期五, 10 四月 2026 09:39:25 +0800
Subject: [PATCH] 和客户同步1.0版本
---
xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/config/log/FeignLoggingAspect.java | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/config/log/FeignLoggingAspect.java b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/config/log/FeignLoggingAspect.java
index 8756eac..f8afa6a 100644
--- a/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/config/log/FeignLoggingAspect.java
+++ b/xp-robotaxi-operation-boot/src/main/java/com/xiaopeng/operation/config/log/FeignLoggingAspect.java
@@ -1,15 +1,20 @@
package com.xiaopeng.operation.config.log;
import com.alibaba.fastjson2.JSON;
+import com.xiaopeng.common.log.config.LogHeaderProperties;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
-import java.util.Arrays;
+import java.util.*;
/**
* Feign 调用日志切面
@@ -27,6 +32,9 @@
@Aspect
@Component
public class FeignLoggingAspect {
+
+ @Autowired
+ private LogHeaderProperties logHeaderProperties;
/**
* 拦截所有带 @FeignClient 注解的接口的所有方法
@@ -46,8 +54,13 @@
Object[] args = pjp.getArgs();
String argsJson = safeToJson(args);
+ String headerStr = extractCurrentHeaders();
- log.info("[Feign] >>> 调用开始 | method={} | args={}", fullMethod, argsJson);
+ if (headerStr != null) {
+ log.info("[Feign] >>> 调用开始 | method={} | headers={} | args={}", fullMethod, headerStr, argsJson);
+ } else {
+ log.info("[Feign] >>> 调用开始 | method={} | args={}", fullMethod, argsJson);
+ }
long start = System.currentTimeMillis();
try {
@@ -80,4 +93,44 @@
return "[序列化失败: " + obj.getClass().getSimpleName() + "]";
}
}
+
+ /**
+ * 从当前请求上下文中提取请求头信息
+ */
+ private String extractCurrentHeaders() {
+ if (!logHeaderProperties.isEnabled()) {
+ return null;
+ }
+ try {
+ ServletRequestAttributes attrs = (ServletRequestAttributes)
+ RequestContextHolder.getRequestAttributes();
+ if (attrs == null) return "{}";
+ HttpServletRequest request = attrs.getRequest();
+ List<String> names = logHeaderProperties.getNames();
+ StringBuilder sb = new StringBuilder("{");
+ boolean first = true;
+ if (names != null && !names.isEmpty()) {
+ for (String name : names) {
+ String value = request.getHeader(name);
+ if (value != null) {
+ if (!first) sb.append(", ");
+ first = false;
+ sb.append(name).append("=").append(value);
+ }
+ }
+ } else {
+ Enumeration<String> headerNames = request.getHeaderNames();
+ while (headerNames != null && headerNames.hasMoreElements()) {
+ String name = headerNames.nextElement();
+ String value = request.getHeader(name);
+ if (!first) sb.append(", ");
+ first = false;
+ sb.append(name).append("=").append(value);
+ }
+ }
+ return sb.append("}").toString();
+ } catch (Exception e) {
+ return "{error: " + e.getMessage() + "}";
+ }
+ }
}
--
Gitblit v1.7.1