optimize: 调整日志输出
This commit is contained in:
parent
317c64019b
commit
e54ea2c275
|
|
@ -1,11 +1,7 @@
|
|||
package com.nflg.product.bomnew.advice;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.nflg.product.bomnew.util.JsonUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.util.JwtUtil;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.core.MethodParameter;
|
||||
|
|
@ -49,14 +45,6 @@ public class LoggingRequestBodyAdvice implements RequestBodyAdvice {
|
|||
bodyContent = reader.lines().collect(Collectors.joining());
|
||||
log.info("请求参数: {}", bodyContent);
|
||||
}
|
||||
log.info("请求头: {}", JsonUtil.toJson(httpInputMessage.getHeaders()));
|
||||
String token = httpInputMessage.getHeaders().getFirst("Authorization");
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
ResultVO result = JwtUtil.parse(token);
|
||||
if (result.getState().equals(STATE.Success.getState())) {
|
||||
log.info("请求用户: {}", JsonUtil.toJson(result.getData()));
|
||||
}
|
||||
}
|
||||
if (StrUtil.isBlank(bodyContent)) {
|
||||
return httpInputMessage;
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,12 @@
|
|||
package com.nflg.product.base.core.config.fillter;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import nflg.product.common.util.JwtUtil;
|
||||
import nflg.product.common.vo.ResultVO;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
|
@ -9,6 +14,7 @@ import org.springframework.web.servlet.HandlerInterceptor;
|
|||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Enumeration;
|
||||
|
||||
/**
|
||||
* 请求拦截器
|
||||
|
|
@ -29,6 +35,23 @@ public class HttpInterceptor implements HandlerInterceptor {
|
|||
String traceId = IdWorker.getIdStr();
|
||||
MDC.put(TRACEID, traceId);
|
||||
log.info("HttpRecord Request,url: " + request.getRequestURL() + " ,method: " + request.getMethod());
|
||||
|
||||
StringBuilder sb = new StringBuilder("请求头: ");
|
||||
Enumeration<String> headerNames = request.getHeaderNames();
|
||||
while (headerNames.hasMoreElements()) {
|
||||
String headerName = headerNames.nextElement();
|
||||
sb.append(StrUtil.format("{}={},", headerName, request.getHeader(headerName)));
|
||||
}
|
||||
log.info(sb.substring(0, sb.length() - 1));
|
||||
|
||||
String token = request.getHeader("Authorization");
|
||||
if (StrUtil.isNotBlank(token)) {
|
||||
ResultVO result = JwtUtil.parse(token);
|
||||
if (result.getState().equals(STATE.Success.getState())) {
|
||||
log.info("请求用户: {}", JSON.toJSONString(result.getData()));
|
||||
}
|
||||
}
|
||||
|
||||
AUTHORIZATION.set(request.getHeader("Authorization"));
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue