Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
promotion-gateway
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
promotion
promotion-gateway
Commits
f190edcd
提交
f190edcd
authored
5月 30, 2024
作者:
李秋林
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
全局日志格式整理,添加token打印
上级
26fbe23d
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
19 行增加
和
193 行删除
+19
-193
RequestLogFilter.java
...va/com/promotion/gateway/filter/log/RequestLogFilter.java
+10
-10
SysLog.java
src/main/java/com/promotion/gateway/filter/log/SysLog.java
+9
-183
没有找到文件。
src/main/java/com/promotion/gateway/filter/log/RequestLogFilter.java
浏览文件 @
f190edcd
...
@@ -51,19 +51,18 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
...
@@ -51,19 +51,18 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
@Override
@Override
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
public
Mono
<
Void
>
filter
(
ServerWebExchange
exchange
,
GatewayFilterChain
chain
)
{
ServerHttpRequest
request
=
exchange
.
getRequest
();
ServerHttpRequest
request
=
exchange
.
getRequest
();
HttpHeaders
headers
=
request
.
getHeaders
();
//请求路径
//请求路径
String
requestUrl
=
request
.
getPath
().
pathWithinApplication
().
value
();
String
requestUrl
=
request
.
getPath
().
pathWithinApplication
().
value
();
Route
route
=
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
GATEWAY_ROUTE_ATTR
);
Route
route
=
exchange
.
getAttribute
(
ServerWebExchangeUtils
.
GATEWAY_ROUTE_ATTR
);
// String ipAddress = IpUtil.getIpAddress(request);
SysLog
sysLog
=
new
SysLog
().
setSchema
(
request
.
getURI
().
getScheme
())
SysLog
sysLog
=
SysLog
.
SysLogBuilder
.
sysLog
().
schema
(
request
.
getURI
().
getScheme
())
.
setRequestMethod
(
request
.
getMethodValue
())
.
requestMethod
(
request
.
getMethodValue
())
.
setRequestPath
(
requestUrl
)
.
requestPath
(
requestUrl
)
.
setTargetServer
(
route
.
getId
())
.
targetServer
(
route
.
getId
())
.
setRequestTime
(
new
Date
())
.
requestTime
(
new
Date
())
.
setToken
(
headers
.
getFirst
(
"Authorization"
));
// .ip(ipAddress)
.
build
();
MediaType
mediaType
=
headers
.
getContentType
();
MediaType
mediaType
=
request
.
getHeaders
().
getContentType
();
if
(
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
if
(
MediaType
.
APPLICATION_JSON
.
isCompatibleWith
(
mediaType
))
{
return
printBodyLog
(
exchange
,
chain
,
sysLog
);
return
printBodyLog
(
exchange
,
chain
,
sysLog
);
}
else
{
}
else
{
...
@@ -185,6 +184,7 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
...
@@ -185,6 +184,7 @@ public class RequestLogFilter implements GlobalFilter, Ordered {
private
void
printLog
(
SysLog
sysLog
)
{
private
void
printLog
(
SysLog
sysLog
)
{
log
.
info
(
"------------ 请求响应 start ------------"
);
log
.
info
(
"------------ 请求响应 start ------------"
);
log
.
info
(
"目标服务:{}:[{}]{}"
,
sysLog
.
getRequestMethod
(),
sysLog
.
getTargetServer
(),
sysLog
.
getRequestPath
());
log
.
info
(
"目标服务:{}:[{}]{}"
,
sysLog
.
getRequestMethod
(),
sysLog
.
getTargetServer
(),
sysLog
.
getRequestPath
());
log
.
info
(
"登录token:{}"
,
sysLog
.
getToken
());
log
.
info
(
"请求参数:{}"
,
sysLog
.
getRequestBody
());
log
.
info
(
"请求参数:{}"
,
sysLog
.
getRequestBody
());
log
.
info
(
"响应信息:{}"
,
sysLog
.
getResponseData
());
log
.
info
(
"响应信息:{}"
,
sysLog
.
getResponseData
());
log
.
info
(
"------------ 请求结束 {} end ------------"
,
sysLog
.
getExecuteTime
());
log
.
info
(
"------------ 请求结束 {} end ------------"
,
sysLog
.
getExecuteTime
());
...
...
src/main/java/com/promotion/gateway/filter/log/SysLog.java
浏览文件 @
f190edcd
package
com
.
promotion
.
gateway
.
filter
.
log
;
package
com
.
promotion
.
gateway
.
filter
.
log
;
import
cn.hutool.core.date.DateUtil
;
import
lombok.AllArgsConstructor
;
import
lombok.Data
;
import
lombok.NoArgsConstructor
;
import
lombok.experimental.Accessors
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.Date
;
import
java.util.Date
;
@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors
(
chain
=
true
)
public
class
SysLog
implements
Serializable
{
public
class
SysLog
implements
Serializable
{
private
static
final
long
serialVersionUID
=
-
4173350480097599017L
;
private
static
final
long
serialVersionUID
=
-
4173350480097599017L
;
...
@@ -28,186 +35,5 @@ public class SysLog implements Serializable {
...
@@ -28,186 +35,5 @@ public class SysLog implements Serializable {
private
Long
executeTime
;
private
Long
executeTime
;
public
String
getTargetServer
()
{
private
String
token
;
return
targetServer
;
}
public
void
setTargetServer
(
String
targetServer
)
{
this
.
targetServer
=
targetServer
;
}
public
String
getRequestPath
()
{
return
requestPath
;
}
public
void
setRequestPath
(
String
requestPath
)
{
this
.
requestPath
=
requestPath
;
}
public
String
getSchema
()
{
return
schema
;
}
public
void
setSchema
(
String
schema
)
{
this
.
schema
=
schema
;
}
public
String
getRequestBody
()
{
return
requestBody
;
}
public
void
setRequestBody
(
String
requestBody
)
{
this
.
requestBody
=
requestBody
;
}
public
String
getResponseData
()
{
return
responseData
;
}
public
void
setResponseData
(
String
responseData
)
{
this
.
responseData
=
responseData
;
}
public
String
getIp
()
{
return
ip
;
}
public
void
setIp
(
String
ip
)
{
this
.
ip
=
ip
;
}
public
Date
getRequestTime
()
{
return
requestTime
;
}
public
void
setRequestTime
(
Date
requestTime
)
{
this
.
requestTime
=
requestTime
;
}
public
Date
getResponseTime
()
{
return
responseTime
;
}
public
void
setResponseTime
(
Date
responseTime
)
{
this
.
responseTime
=
responseTime
;
}
public
Long
getExecuteTime
()
{
return
executeTime
;
}
public
void
setExecuteTime
(
Long
executeTime
)
{
this
.
executeTime
=
executeTime
;
}
public
String
getRequestMethod
()
{
return
requestMethod
;
}
public
void
setRequestMethod
(
String
requestMethod
)
{
this
.
requestMethod
=
requestMethod
;
}
@Override
public
String
toString
()
{
return
"\n SysLog{"
+
" targetServer='"
+
targetServer
+
'\''
+
",\n"
+
" requestPath='"
+
requestPath
+
'\''
+
",\n"
+
" requestMethod='"
+
requestMethod
+
'\''
+
",\n"
+
" schema='"
+
schema
+
'\''
+
",\n"
+
" requestBody='"
+
requestBody
+
'\''
+
",\n"
+
" responseData='"
+
responseData
+
'\''
+
",\n"
+
" ip='"
+
ip
+
'\''
+
",\n"
+
" requestTime="
+
DateUtil
.
formatDateTime
(
requestTime
)
+
",\n"
+
" responseTime="
+
DateUtil
.
formatDateTime
(
responseTime
)+
",\n"
+
" executeTime="
+
executeTime
+
'}'
;
}
public
static
final
class
SysLogBuilder
{
private
String
targetServer
;
private
String
requestPath
;
private
String
requestMethod
;
private
String
schema
;
private
String
requestBody
;
private
String
responseData
;
private
String
ip
;
private
Date
requestTime
;
private
Date
responseTime
;
private
Long
executeTime
;
private
SysLogBuilder
()
{
}
public
static
SysLogBuilder
sysLog
()
{
return
new
SysLogBuilder
();
}
public
SysLogBuilder
targetServer
(
String
targetServer
)
{
this
.
targetServer
=
targetServer
;
return
this
;
}
public
SysLogBuilder
requestMethod
(
String
requestMethod
)
{
this
.
requestMethod
=
requestMethod
;
return
this
;
}
public
SysLogBuilder
requestPath
(
String
requestPath
)
{
this
.
requestPath
=
requestPath
;
return
this
;
}
public
SysLogBuilder
schema
(
String
schema
)
{
this
.
schema
=
schema
;
return
this
;
}
public
SysLogBuilder
requestBody
(
String
requestBody
)
{
this
.
requestBody
=
requestBody
;
return
this
;
}
public
SysLogBuilder
responseData
(
String
responseData
)
{
this
.
responseData
=
responseData
;
return
this
;
}
public
SysLogBuilder
ip
(
String
ip
)
{
this
.
ip
=
ip
;
return
this
;
}
public
SysLogBuilder
requestTime
(
Date
requestTime
)
{
this
.
requestTime
=
requestTime
;
return
this
;
}
public
SysLogBuilder
responseTime
(
Date
responseTime
)
{
this
.
responseTime
=
responseTime
;
return
this
;
}
public
SysLogBuilder
executeTime
(
Long
executeTime
)
{
this
.
executeTime
=
executeTime
;
return
this
;
}
public
SysLog
build
()
{
SysLog
sysLog
=
new
SysLog
();
sysLog
.
setTargetServer
(
targetServer
);
sysLog
.
setRequestMethod
(
requestMethod
);
sysLog
.
setRequestPath
(
requestPath
);
sysLog
.
setSchema
(
schema
);
sysLog
.
setRequestBody
(
requestBody
);
sysLog
.
setResponseData
(
responseData
);
sysLog
.
setIp
(
ip
);
sysLog
.
setRequestTime
(
requestTime
);
sysLog
.
setResponseTime
(
responseTime
);
sysLog
.
setExecuteTime
(
executeTime
);
return
sysLog
;
}
}
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论