-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 添加操作日志是否忽略支持记录当前参数配置;登录接口记录操作日志用户认证信息 #280
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9807583
refactor: 去掉登录接口忽略日志记载注释
goten7 3e858b2
feat: 添加操作日志是否忽略支持记录当前参数配置
goten7 56ad57d
feat: 登录接口记录操作日志用户认证信息
goten7 e19dc43
feat: 优化日志记录上下文缺失的情况
goten7 996990c
feat: 优化参数为数组
goten7 53e9c78
feat: 优化参数为数组
goten7 ebd4ec8
feat: 优化
goten7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,10 @@ | |
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* 使用AOP记录访问日志,并触发{@link AccessLoggerListener#onLogger(AccessLoggerInfo)} | ||
|
@@ -61,7 +65,8 @@ protected AccessLoggerInfo createLogger(MethodInterceptorHolder holder) { | |
info.setId(IDGenerator.MD5.generate()); | ||
|
||
info.setRequestTime(System.currentTimeMillis()); | ||
LoggerDefine define = loggerParsers.stream() | ||
LoggerDefine define = loggerParsers | ||
.stream() | ||
.filter(parser -> parser.support(ClassUtils.getUserClass(holder.getTarget()), holder.getMethod())) | ||
.findAny() | ||
.map(parser -> parser.parse(holder)) | ||
|
@@ -71,7 +76,7 @@ protected AccessLoggerInfo createLogger(MethodInterceptorHolder holder) { | |
info.setAction(define.getAction()); | ||
info.setDescribe(define.getDescribe()); | ||
} | ||
info.setParameters(holder.getNamedArguments()); | ||
info.setParameters(parseParameter(holder)); | ||
info.setTarget(holder.getTarget().getClass()); | ||
info.setMethod(holder.getMethod()); | ||
|
||
|
@@ -86,6 +91,22 @@ protected AccessLoggerInfo createLogger(MethodInterceptorHolder holder) { | |
|
||
} | ||
|
||
private Map<String, Object> parseParameter(MethodInterceptorHolder holder) { | ||
Predicate<String> ignoreParameter = loggerParsers | ||
.stream() | ||
.map(parser -> parser.ignoreParameter(holder)) | ||
.filter(Objects::nonNull) | ||
.reduce(Predicate::and) | ||
.orElse(p -> false); | ||
|
||
return holder | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 使用 |
||
.getNamedArguments() | ||
.entrySet() | ||
.stream() | ||
.filter(entry -> ignoreParameter.test(entry.getKey())) | ||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
@Override | ||
public int getOrder() { | ||
return Ordered.HIGHEST_PRECEDENCE; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,10 @@ | |
* @return 是否取消日志记录, 如果不想记录某些方法或者类, 设置为true即可 | ||
*/ | ||
boolean ignore() default false; | ||
|
||
/** | ||
* @return 忽略记载方法的请求参数 | ||
* <p>如果不想记录方法全部或某些参数,则可以配置返回*或者对应参数名(多个用逗号分割)</p> | ||
*/ | ||
String ignoreParameter() default ""; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 建议使用数组,并且支持 * 进行通配。 |
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单独写一个类来处理此事件