Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
C
cocktail-party-server
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
cocktail-party
cocktail-party-server
Commits
61caa796
提交
61caa796
authored
2月 20, 2023
作者:
RuoYi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
日志注解支持排除指定的请求参数
上级
a5f95edd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
15 行增加
和
9 行删除
+15
-9
Log.java
...common/src/main/java/com/ruoyi/common/annotation/Log.java
+6
-1
LogAspect.java
.../src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
+9
-8
没有找到文件。
ruoyi-common/src/main/java/com/ruoyi/common/annotation/Log.java
浏览文件 @
61caa796
...
@@ -20,7 +20,7 @@ import com.ruoyi.common.enums.OperatorType;
...
@@ -20,7 +20,7 @@ import com.ruoyi.common.enums.OperatorType;
public
@interface
Log
public
@interface
Log
{
{
/**
/**
* 模块
* 模块
*/
*/
public
String
title
()
default
""
;
public
String
title
()
default
""
;
...
@@ -43,4 +43,9 @@ public @interface Log
...
@@ -43,4 +43,9 @@ public @interface Log
* 是否保存响应的参数
* 是否保存响应的参数
*/
*/
public
boolean
isSaveResponseData
()
default
true
;
public
boolean
isSaveResponseData
()
default
true
;
/**
* 排除指定的请求参数
*/
public
String
[]
excludeParamNames
()
default
{};
}
}
ruoyi-framework/src/main/java/com/ruoyi/framework/aspectj/LogAspect.java
浏览文件 @
61caa796
...
@@ -4,6 +4,7 @@ import java.util.Collection;
...
@@ -4,6 +4,7 @@ import java.util.Collection;
import
java.util.Map
;
import
java.util.Map
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
import
javax.servlet.http.HttpServletResponse
;
import
org.apache.commons.lang3.ArrayUtils
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.AfterReturning
;
import
org.aspectj.lang.annotation.AfterThrowing
;
import
org.aspectj.lang.annotation.AfterThrowing
;
...
@@ -146,7 +147,7 @@ public class LogAspect
...
@@ -146,7 +147,7 @@ public class LogAspect
if
(
log
.
isSaveRequestData
())
if
(
log
.
isSaveRequestData
())
{
{
// 获取参数的信息,传入到数据库中。
// 获取参数的信息,传入到数据库中。
setRequestValue
(
joinPoint
,
operLog
);
setRequestValue
(
joinPoint
,
operLog
,
log
.
excludeParamNames
()
);
}
}
// 是否需要保存response,参数和值
// 是否需要保存response,参数和值
if
(
log
.
isSaveResponseData
()
&&
StringUtils
.
isNotNull
(
jsonResult
))
if
(
log
.
isSaveResponseData
()
&&
StringUtils
.
isNotNull
(
jsonResult
))
...
@@ -161,25 +162,25 @@ public class LogAspect
...
@@ -161,25 +162,25 @@ public class LogAspect
* @param operLog 操作日志
* @param operLog 操作日志
* @throws Exception 异常
* @throws Exception 异常
*/
*/
private
void
setRequestValue
(
JoinPoint
joinPoint
,
SysOperLog
operLog
)
throws
Exception
private
void
setRequestValue
(
JoinPoint
joinPoint
,
SysOperLog
operLog
,
String
[]
excludeParamNames
)
throws
Exception
{
{
String
requestMethod
=
operLog
.
getRequestMethod
();
String
requestMethod
=
operLog
.
getRequestMethod
();
if
(
HttpMethod
.
PUT
.
name
().
equals
(
requestMethod
)
||
HttpMethod
.
POST
.
name
().
equals
(
requestMethod
))
if
(
HttpMethod
.
PUT
.
name
().
equals
(
requestMethod
)
||
HttpMethod
.
POST
.
name
().
equals
(
requestMethod
))
{
{
String
params
=
argsArrayToString
(
joinPoint
.
getArgs
());
String
params
=
argsArrayToString
(
joinPoint
.
getArgs
()
,
excludeParamNames
);
operLog
.
setOperParam
(
StringUtils
.
substring
(
params
,
0
,
2000
));
operLog
.
setOperParam
(
StringUtils
.
substring
(
params
,
0
,
2000
));
}
}
else
else
{
{
Map
<?,
?>
paramsMap
=
ServletUtils
.
getParamMap
(
ServletUtils
.
getRequest
());
Map
<?,
?>
paramsMap
=
ServletUtils
.
getParamMap
(
ServletUtils
.
getRequest
());
operLog
.
setOperParam
(
StringUtils
.
substring
(
JSON
.
toJSONString
(
paramsMap
,
excludePropertyPreFilter
()),
0
,
2000
));
operLog
.
setOperParam
(
StringUtils
.
substring
(
JSON
.
toJSONString
(
paramsMap
,
excludePropertyPreFilter
(
excludeParamNames
)),
0
,
2000
));
}
}
}
}
/**
/**
* 参数拼装
* 参数拼装
*/
*/
private
String
argsArrayToString
(
Object
[]
paramsArray
)
private
String
argsArrayToString
(
Object
[]
paramsArray
,
String
[]
excludeParamNames
)
{
{
String
params
=
""
;
String
params
=
""
;
if
(
paramsArray
!=
null
&&
paramsArray
.
length
>
0
)
if
(
paramsArray
!=
null
&&
paramsArray
.
length
>
0
)
...
@@ -190,7 +191,7 @@ public class LogAspect
...
@@ -190,7 +191,7 @@ public class LogAspect
{
{
try
try
{
{
String
jsonObj
=
JSON
.
toJSONString
(
o
,
excludePropertyPreFilter
());
String
jsonObj
=
JSON
.
toJSONString
(
o
,
excludePropertyPreFilter
(
excludeParamNames
));
params
+=
jsonObj
.
toString
()
+
" "
;
params
+=
jsonObj
.
toString
()
+
" "
;
}
}
catch
(
Exception
e
)
catch
(
Exception
e
)
...
@@ -205,9 +206,9 @@ public class LogAspect
...
@@ -205,9 +206,9 @@ public class LogAspect
/**
/**
* 忽略敏感属性
* 忽略敏感属性
*/
*/
public
PropertyPreExcludeFilter
excludePropertyPreFilter
()
public
PropertyPreExcludeFilter
excludePropertyPreFilter
(
String
[]
excludeParamNames
)
{
{
return
new
PropertyPreExcludeFilter
().
addExcludes
(
EXCLUDE_PROPERTIES
);
return
new
PropertyPreExcludeFilter
().
addExcludes
(
ArrayUtils
.
addAll
(
EXCLUDE_PROPERTIES
,
excludeParamNames
)
);
}
}
/**
/**
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论