mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +08:00
fix(log/httptrace-pro): 修复 IP 配置解析错误,并缩小日志异常影响范围
This commit is contained in:
@@ -82,8 +82,8 @@ public class ProjectProperties {
|
||||
public static final boolean IP_ADDR_LOCAL_PARSE_ENABLED;
|
||||
|
||||
static {
|
||||
String underlineCaseProperty = SpringUtil.getProperty("ip-addr-local-parse-enabled");
|
||||
String camelCaseProperty = SpringUtil.getProperty("ipAddrLocalParseEnabled");
|
||||
String underlineCaseProperty = SpringUtil.getProperty("project.ip-addr-local-parse-enabled");
|
||||
String camelCaseProperty = SpringUtil.getProperty("project.ipAddrLocalParseEnabled");
|
||||
IP_ADDR_LOCAL_PARSE_ENABLED = Convert.toBool(underlineCaseProperty, false) || Convert.toBool(camelCaseProperty, false);
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,9 @@
|
||||
|
||||
package top.charles7c.continew.starter.core.util;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.http.HtmlUtil;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
@@ -28,6 +30,9 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
|
||||
import net.dreamlu.mica.ip2region.core.IpInfo;
|
||||
import top.charles7c.continew.starter.core.autoconfigure.project.ProjectProperties;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* IP 工具类
|
||||
@@ -86,7 +91,9 @@ public class IpUtils {
|
||||
Ip2regionSearcher ip2regionSearcher = SpringUtil.getBean(Ip2regionSearcher.class);
|
||||
IpInfo ipInfo = ip2regionSearcher.memorySearch(ip);
|
||||
if (null != ipInfo) {
|
||||
return ipInfo.getAddress();
|
||||
Set<String> regionSet = CollUtil.newLinkedHashSet(ipInfo.getAddress(), ipInfo.getIsp());
|
||||
regionSet.removeIf(StrUtil::isBlank);
|
||||
return String.join(StringConstants.SPACE, regionSet);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@@ -69,19 +69,23 @@ public class LogInterceptor implements HandlerInterceptor {
|
||||
timestampTtl.remove();
|
||||
Set<Include> includeSet = properties.getInclude();
|
||||
RecordableServletHttpRequest sourceRequest = new RecordableServletHttpRequest(request);
|
||||
LogRecord.Started startedLogRecord = LogRecord.start(timestamp, sourceRequest);
|
||||
RecordableServletHttpResponse sourceResponse = new RecordableServletHttpResponse(response, response.getStatus());
|
||||
LogRecord finishedLogRecord = startedLogRecord.finish(sourceResponse, includeSet);
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
if (includeSet.contains(Include.DESCRIPTION)) {
|
||||
// 记录日志描述
|
||||
this.logDescription(finishedLogRecord, handlerMethod);
|
||||
try {
|
||||
LogRecord.Started startedLogRecord = LogRecord.start(timestamp, sourceRequest);
|
||||
RecordableServletHttpResponse sourceResponse = new RecordableServletHttpResponse(response, response.getStatus());
|
||||
LogRecord finishedLogRecord = startedLogRecord.finish(sourceResponse, includeSet);
|
||||
HandlerMethod handlerMethod = (HandlerMethod) handler;
|
||||
if (includeSet.contains(Include.DESCRIPTION)) {
|
||||
// 记录日志描述
|
||||
this.logDescription(finishedLogRecord, handlerMethod);
|
||||
}
|
||||
if (includeSet.contains(Include.MODULE)) {
|
||||
// 记录所属模块
|
||||
this.logModule(finishedLogRecord, handlerMethod);
|
||||
}
|
||||
dao.add(finishedLogRecord);
|
||||
} catch (Exception ex) {
|
||||
log.error("Logging http log occurred an error: {}.", ex.getMessage(), ex);
|
||||
}
|
||||
if (includeSet.contains(Include.MODULE)) {
|
||||
// 记录所属模块
|
||||
this.logModule(finishedLogRecord, handlerMethod);
|
||||
}
|
||||
dao.add(finishedLogRecord);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user