Commit 8dd17521 authored by 赵啸非's avatar 赵啸非

修改访问日志

parent 9bad6fd6
......@@ -7,7 +7,7 @@ import com.mortals.framework.model.BaseEntityLong;
* 访问日志Pdu对象
*
* @author zxfei
* @date 2022-08-19
* @date 2022-08-22
*/
public class AccessLogPdu extends BaseEntityLong {
......@@ -49,10 +49,6 @@ public class AccessLogPdu extends BaseEntityLong {
* 请求方式
*/
private String method;
/**
* 协议
*/
private String schema;
/**
* 用户浏览器UA
*/
......@@ -85,6 +81,10 @@ public class AccessLogPdu extends BaseEntityLong {
* 持续时间,单位毫秒
*/
private Long duration;
/**
* 协议
*/
private String schemaData;
/** 开始 主键ID */
private Long idStart;
......@@ -143,9 +143,6 @@ public class AccessLogPdu extends BaseEntityLong {
/** 请求方式 */
private List<String> methodList;
/** 协议 */
private List<String> schemaList;
/** 用户浏览器UA */
private List<String> uaList;
......@@ -206,6 +203,9 @@ public class AccessLogPdu extends BaseEntityLong {
/** 结束 创建时间 */
private String createTimeEnd;
/** 协议 */
private List<String> schemaDataList;
/** OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4) */
private List<AccessLogPdu> orConditionList;
......@@ -340,20 +340,6 @@ public class AccessLogPdu extends BaseEntityLong {
public void setMethod(String method){
this.method = method;
}
/**
* 获取 协议
* @return String
*/
public String getSchema(){
return schema;
}
/**
* 设置 协议
* @param schema
*/
public void setSchema(String schema){
this.schema = schema;
}
/**
* 获取 用户浏览器UA
* @return String
......@@ -466,6 +452,20 @@ public class AccessLogPdu extends BaseEntityLong {
public void setDuration(Long duration){
this.duration = duration;
}
/**
* 获取 协议
* @return String
*/
public String getSchemaData(){
return schemaData;
}
/**
* 设置 协议
* @param schemaData
*/
public void setSchemaData(String schemaData){
this.schemaData = schemaData;
}
/**
* 获取 开始 主键ID
......@@ -764,21 +764,6 @@ public class AccessLogPdu extends BaseEntityLong {
public void setMethodList(List<String> methodList){
this.methodList = methodList;
}
/**
* 获取 协议
* @return schemaList
*/
public List<String> getSchemaList(){
return this.schemaList;
}
/**
* 设置 协议
* @param schemaList
*/
public void setSchemaList(List<String> schemaList){
this.schemaList = schemaList;
}
/**
* 获取 用户浏览器UA
* @return uaList
......@@ -1095,6 +1080,21 @@ public class AccessLogPdu extends BaseEntityLong {
this.createTimeEnd = createTimeEnd;
}
/**
* 获取 协议
* @return schemaDataList
*/
public List<String> getSchemaDataList(){
return this.schemaDataList;
}
/**
* 设置 协议
* @param schemaDataList
*/
public void setSchemaDataList(List<String> schemaDataList){
this.schemaDataList = schemaDataList;
}
/**
* 设置 主键ID
* @param id
......@@ -1364,25 +1364,6 @@ public class AccessLogPdu extends BaseEntityLong {
}
/**
* 设置 协议
* @param schema
*/
public AccessLogPdu schema(String schema){
setSchema(schema);
return this;
}
/**
* 设置 协议
* @param schemaList
*/
public AccessLogPdu schemaList(List<String> schemaList){
this.schemaList = schemaList;
return this;
}
/**
* 设置 用户浏览器UA
* @param ua
......@@ -1553,6 +1534,25 @@ public class AccessLogPdu extends BaseEntityLong {
/**
* 设置 协议
* @param schemaData
*/
public AccessLogPdu schemaData(String schemaData){
setSchemaData(schemaData);
return this;
}
/**
* 设置 协议
* @param schemaDataList
*/
public AccessLogPdu schemaDataList(List<String> schemaDataList){
this.schemaDataList = schemaDataList;
return this;
}
/**
* 获取 OR条件集合,列表项之间是OR,项内容之间是AND,如:(list[0].1 and list[0].2) or (list[1].3 and list[1].4)
* @return orConditionList
......@@ -1621,8 +1621,6 @@ public class AccessLogPdu extends BaseEntityLong {
this.method = "";
this.schema = "http";
this.ua = "";
this.uri = "";
......@@ -1638,5 +1636,7 @@ public class AccessLogPdu extends BaseEntityLong {
this.responseTime = null;
this.duration = null;
this.schemaData = "http";
}
}
\ No newline at end of file
......@@ -88,36 +88,23 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
Route route = getGatewayRoute(exchange);
// String ipAddress = WebUtils.get(request);
String ipAddress = IpUtils.getRealIpAddress(exchange.getRequest());
Map<String, String> headers = exchange.getRequest().getHeaders().toSingleValueMap();
AccessLogPdu accessLogPdu = new AccessLogPdu();
accessLogPdu.initAttrValue();
accessLogPdu.setAppName(appName);
accessLogPdu.setTraceID(headers.getOrDefault(TRACE_ID,""));
accessLogPdu.setPspanId(Integer.parseInt(headers.getOrDefault(PSPAN_ID,"0")));
accessLogPdu.setSpanId(Integer.parseInt(headers.getOrDefault(SPAN_ID,"0")));
accessLogPdu.setSchema(request.getURI().getScheme());
accessLogPdu.setSchemaData(request.getURI().getScheme());
accessLogPdu.setHostName(NetUtil.getLocalHostName());
accessLogPdu.setUri(requestPath);
accessLogPdu.setTargetServer(route.getId());
accessLogPdu.setRequestIp(IpUtils.getRealIpAddress(exchange.getRequest()));
accessLogPdu.setUa(headers.getOrDefault("User-Agent",""));
accessLogPdu.setRequestTime(new Date());
accessLogPdu.setLogTime(new Date());
accessLogPdu.setMethod(request.getMethodValue());
//accessLogPdu.setRequestData(paramStr);
// GatewayLog gatewayLog = new GatewayLog();
// gatewayLog.setSchema(request.getURI().getScheme());
// gatewayLog.setRequestMethod(request.getMethodValue());
// gatewayLog.setRequestPath(requestPath);
// gatewayLog.setTargetServer(route.getId());
// gatewayLog.setRequestTime(new Date());
// gatewayLog.setIp(ipAddress);
MediaType mediaType = request.getHeaders().getContentType();
if (MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(mediaType) || MediaType.APPLICATION_JSON.isCompatibleWith(mediaType)) {
return writeBodyLog(exchange, chain, accessLogPdu);
......@@ -260,6 +247,7 @@ public class AccessLogFilter implements GlobalFilter, Ordered {
// accessLogPdu.setResponseTime(responseTime);
// 计算执行时间
long executeTime = (responseTime.getTime() - accessLogPdu.getRequestTime().getTime());
accessLogPdu.setResponseTime(responseTime);
accessLogPdu.setDuration(executeTime);
// 获取响应类型,如果是 json 就打印
String originalResponseContentType = exchange.getAttribute(ServerWebExchangeUtils.ORIGINAL_RESPONSE_CONTENT_TYPE_ATTR);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment