mirror of
https://github.com/continew-org/continew-starter.git
synced 2025-09-09 08:57:17 +08:00
feat(log): 新增日志模块 - HttpTracePro(Spring Boot Actuator HttpTrace 定制增强版)
This commit is contained in:
@@ -45,26 +45,26 @@ public class IpUtils {
|
||||
private static final String IP_URL = "http://whois.pconline.com.cn/ipJson.jsp?ip=%s&json=true";
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息
|
||||
* 查询 IP 归属地
|
||||
*
|
||||
* @param ip IP 地址
|
||||
* @return 归属地信息
|
||||
* @return IP 归属地
|
||||
*/
|
||||
public static String getCityInfo(String ip) {
|
||||
public static String getAddress(String ip) {
|
||||
if (ProjectProperties.IP_ADDR_LOCAL_PARSE_ENABLED) {
|
||||
return getLocalCityInfo(ip);
|
||||
return getAddressByLocal(ip);
|
||||
} else {
|
||||
return getHttpCityInfo(ip);
|
||||
return getAddressByHttp(ip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息(网络解析)
|
||||
* 查询 IP 归属地(网络解析)
|
||||
*
|
||||
* @param ip IP 地址
|
||||
* @return 归属地信息
|
||||
* @return IP 归属地
|
||||
*/
|
||||
public static String getHttpCityInfo(String ip) {
|
||||
public static String getAddressByHttp(String ip) {
|
||||
if (isInnerIp(ip)) {
|
||||
return "内网IP";
|
||||
}
|
||||
@@ -74,12 +74,12 @@ public class IpUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据 IP 获取归属地信息(本地解析)
|
||||
* 查询 IP 归属地(本地库解析)
|
||||
*
|
||||
* @param ip IP 地址
|
||||
* @return 归属地信息
|
||||
* @return IP 归属地
|
||||
*/
|
||||
public static String getLocalCityInfo(String ip) {
|
||||
public static String getAddressByLocal(String ip) {
|
||||
if (isInnerIp(ip)) {
|
||||
return "内网IP";
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ import lombok.AccessLevel;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.web.context.request.RequestContextHolder;
|
||||
import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import top.charles7c.continew.starter.core.constant.StringConstants;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -64,8 +65,42 @@ public class ServletUtils {
|
||||
if (null == request) {
|
||||
return null;
|
||||
}
|
||||
UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent"));
|
||||
return userAgent.getBrowser().getName() + " " + userAgent.getVersion();
|
||||
return getBrowser(request.getHeader("User-Agent"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取浏览器及其版本信息
|
||||
*
|
||||
* @param userAgentString User-Agent 字符串
|
||||
* @return 浏览器及其版本信息
|
||||
*/
|
||||
public static String getBrowser(String userAgentString) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(userAgentString);
|
||||
return userAgent.getBrowser().getName() + StringConstants.SPACE + userAgent.getVersion();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统
|
||||
*
|
||||
* @param request 请求对象
|
||||
* @return 操作系统
|
||||
*/
|
||||
public static String getOs(HttpServletRequest request) {
|
||||
if (null == request) {
|
||||
return null;
|
||||
}
|
||||
return getOs(request.getHeader("User-Agent"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取操作系统
|
||||
*
|
||||
* @param userAgentString User-Agent 字符串
|
||||
* @return 操作系统
|
||||
*/
|
||||
public static String getOs(String userAgentString) {
|
||||
UserAgent userAgent = UserAgentUtil.parse(userAgentString);
|
||||
return userAgent.getOs().getName();
|
||||
}
|
||||
|
||||
private static ServletRequestAttributes getServletRequestAttributes() {
|
||||
|
Reference in New Issue
Block a user