优化http日志采集
This commit is contained in:
@@ -97,24 +97,29 @@ public class HttpLogFilter extends BaseFilter implements Ordered, BaseParams {
|
||||
// 记录请求日志
|
||||
LogBus.init(LogLevel.INFO, LogBusBaseType.HTTP_REQUEST).data(log).save();
|
||||
|
||||
// 包装请求和响应
|
||||
// 包装请求
|
||||
ContentCachingRequestWrapper requestWrapper = new ContentCachingRequestWrapper(request, DEFAULT_CACHE_LIMIT);
|
||||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
||||
|
||||
// 响应数据
|
||||
Object respData;
|
||||
if (PathPatternUtils.match(RESP_WHITE_LIST, uri)) {
|
||||
// 处理请求
|
||||
filterChain.doFilter(requestWrapper, response);
|
||||
respData = "ignore";
|
||||
} else {
|
||||
// 包装响应
|
||||
ContentCachingResponseWrapper responseWrapper = new ContentCachingResponseWrapper(response);
|
||||
// 处理请求
|
||||
filterChain.doFilter(requestWrapper, responseWrapper);
|
||||
// 获取响应内容
|
||||
respData = getContent(responseWrapper.getContentAsByteArray());
|
||||
// 将内容复制回原始响应
|
||||
responseWrapper.copyBodyToResponse();
|
||||
}
|
||||
|
||||
// 获取请求参数
|
||||
Object reqParam = getContent(requestWrapper.getContentAsByteArray());
|
||||
Object respData;
|
||||
if (!PathPatternUtils.match(RESP_WHITE_LIST, uri)) {
|
||||
// 获取响应内容
|
||||
respData = getContent(responseWrapper.getContentAsByteArray());
|
||||
} else {
|
||||
respData = "ignore";
|
||||
}
|
||||
// 将内容复制回原始响应
|
||||
responseWrapper.copyBodyToResponse();
|
||||
|
||||
// 保存日志
|
||||
log.put("reqBody", reqParam);
|
||||
log.put("respData", respData);
|
||||
|
||||
Reference in New Issue
Block a user