mirror of https://gitee.com/maxjhandsome/pig
🎨 Improving structure / format of the code. 格式化代码符合工程规范
This commit is contained in:
parent
62a216571a
commit
3070c084a3
|
@ -58,7 +58,6 @@ public class SysLogUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取客户端
|
* 获取客户端
|
||||||
*
|
|
||||||
* @return clientId
|
* @return clientId
|
||||||
*/
|
*/
|
||||||
private String getClientId(HttpServletRequest request) {
|
private String getClientId(HttpServletRequest request) {
|
||||||
|
@ -69,7 +68,8 @@ public class SysLogUtils {
|
||||||
}
|
}
|
||||||
if (authentication instanceof UsernamePasswordAuthenticationToken) {
|
if (authentication instanceof UsernamePasswordAuthenticationToken) {
|
||||||
BasicAuthenticationConverter basicAuthenticationConverter = new BasicAuthenticationConverter();
|
BasicAuthenticationConverter basicAuthenticationConverter = new BasicAuthenticationConverter();
|
||||||
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = basicAuthenticationConverter.convert(request);
|
UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken = basicAuthenticationConverter
|
||||||
|
.convert(request);
|
||||||
if (usernamePasswordAuthenticationToken != null) {
|
if (usernamePasswordAuthenticationToken != null) {
|
||||||
return usernamePasswordAuthenticationToken.getName();
|
return usernamePasswordAuthenticationToken.getName();
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,6 @@ public class SysLogUtils {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户名称
|
* 获取用户名称
|
||||||
*
|
|
||||||
* @return username
|
* @return username
|
||||||
*/
|
*/
|
||||||
private String getUsername() {
|
private String getUsername() {
|
||||||
|
@ -89,4 +88,5 @@ public class SysLogUtils {
|
||||||
}
|
}
|
||||||
return authentication.getName();
|
return authentication.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -16,8 +16,7 @@ import java.util.List;
|
||||||
* <p>
|
* <p>
|
||||||
* 全局拦截器,作用所有的微服务
|
* 全局拦截器,作用所有的微服务
|
||||||
* <p>
|
* <p>
|
||||||
* 1. 对请求的API调用过滤,记录接口的请求时间,方便日志审计、告警、分析等运维操作
|
* 1. 对请求的API调用过滤,记录接口的请求时间,方便日志审计、告警、分析等运维操作 2. 后期可以扩展对接其他日志系统
|
||||||
* 2. 后期可以扩展对接其他日志系统
|
|
||||||
* <p>
|
* <p>
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@ -25,15 +24,14 @@ import java.util.List;
|
||||||
public class ApiLoggingFilter implements GlobalFilter, Ordered {
|
public class ApiLoggingFilter implements GlobalFilter, Ordered {
|
||||||
|
|
||||||
private static final String START_TIME = "startTime";
|
private static final String START_TIME = "startTime";
|
||||||
private static final String X_REAL_IP = "X-Real-IP";//nginx需要配置
|
|
||||||
|
private static final String X_REAL_IP = "X-Real-IP";// nginx需要配置
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
|
||||||
String info = String.format("Method:{%s} Host:{%s} Path:{%s} Query:{%s}",
|
String info = String.format("Method:{%s} Host:{%s} Path:{%s} Query:{%s}",
|
||||||
exchange.getRequest().getMethod().name(),
|
exchange.getRequest().getMethod().name(), exchange.getRequest().getURI().getHost(),
|
||||||
exchange.getRequest().getURI().getHost(),
|
exchange.getRequest().getURI().getPath(), exchange.getRequest().getQueryParams());
|
||||||
exchange.getRequest().getURI().getPath(),
|
|
||||||
exchange.getRequest().getQueryParams());
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug(info);
|
log.debug(info);
|
||||||
}
|
}
|
||||||
|
@ -45,8 +43,9 @@ public class ApiLoggingFilter implements GlobalFilter, Ordered {
|
||||||
List<String> ips = exchange.getRequest().getHeaders().get(X_REAL_IP);
|
List<String> ips = exchange.getRequest().getHeaders().get(X_REAL_IP);
|
||||||
String ip = ips != null ? ips.get(0) : null;
|
String ip = ips != null ? ips.get(0) : null;
|
||||||
String api = exchange.getRequest().getURI().getRawPath();
|
String api = exchange.getRequest().getURI().getRawPath();
|
||||||
int code = exchange.getResponse().getStatusCode() != null ? exchange.getResponse().getStatusCode().value() : 500;
|
int code = exchange.getResponse().getStatusCode() != null
|
||||||
//当前仅记录日志,后续可以添加日志队列,来过滤请求慢的接口
|
? exchange.getResponse().getStatusCode().value() : 500;
|
||||||
|
// 当前仅记录日志,后续可以添加日志队列,来过滤请求慢的接口
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("来自IP地址:{}的请求接口:{},响应状态码:{},请求耗时:{}ms", ip, api, code, executeTime);
|
log.debug("来自IP地址:{}的请求接口:{},响应状态码:{},请求耗时:{}ms", ip, api, code, executeTime);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue