Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
order-group-application
order-group
Commits
e4011340
Commit
e4011340
authored
Jul 23, 2021
by
ping.wu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
订单聚合层Feign打印日志修改
parent
6223961f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
11 deletions
+14
-11
order-application-service/src/main/java/cn/freemud/annotations/LogIgnoreFeign.java
+1
-1
order-application-service/src/main/java/cn/freemud/aop/LogIgnoreFeignAspect.java
+13
-10
No files found.
order-application-service/src/main/java/cn/freemud/annotations/LogIgnoreFeign.java
View file @
e4011340
...
...
@@ -16,7 +16,7 @@ public @interface LogIgnoreFeign {
* 是否打印日志,true打印,false不打印,注意设置成false状态码和状态码信息都不会打印
* @return
*/
boolean
printLog
()
default
tru
e
;
boolean
printLog
()
default
fals
e
;
/**
* printLog 设置成true的时候,可以排除哪些状态码的响应不用打印响应报文,只会打印状态码
...
...
order-application-service/src/main/java/cn/freemud/aop/LogIgnoreFeignAspect.java
View file @
e4011340
...
...
@@ -4,10 +4,11 @@ import cn.freemud.annotations.LogIgnore;
import
cn.freemud.annotations.LogIgnoreFeign
;
import
cn.freemud.entities.vo.ThirdPartLogVo
;
import
cn.freemud.utils.AppLogUtil
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.freemud.application.sdk.api.base.SDKCommonBaseContextWare
;
import
com.freemud.application.sdk.api.log.LogThreadLocal
;
import
com.freemud.application.sdk.api.log.ThirdPartyLog
;
import
lombok.extern.slf4j.Slf4j
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
import
org.aspectj.lang.annotation.Around
;
...
...
@@ -30,7 +31,6 @@ import java.lang.reflect.Method;
@Aspect
@Component
@Slf4j
public
class
LogIgnoreFeignAspect
{
/**
* 是否打印响应报文日志,默认是false,若为true会覆盖注解里面的{@link LogIgnore}配置,输出响应报文里面所有的信息
...
...
@@ -61,14 +61,17 @@ public class LogIgnoreFeignAspect {
Method
currentMethod
=
sig
.
getDeclaringType
().
getDeclaredMethod
(
msig
.
getName
(),
msig
.
getParameterTypes
());
Object
logReult
=
result
;
ThirdPartLogVo
thirdPartLogVo
=
AppLogUtil
.
createThirdPartLogVo
(
joinPoint
);
// 打印第三方出参日志
if
(!
this
.
printFeignResponseBodyLog
)
{
LogIgnoreFeign
logIgnore
=
currentMethod
.
getAnnotation
(
LogIgnoreFeign
.
class
);
if
(
logIgnore
!=
null
&&
logIgnore
.
printLog
())
{
String
statusCodeValue
=
org
.
apache
.
commons
.
beanutils
.
BeanUtils
.
getProperty
(
result
,
logIgnore
.
statusCodeFieldName
());
String
messageValue
=
org
.
apache
.
commons
.
beanutils
.
BeanUtils
.
getProperty
(
result
,
logIgnore
.
messageFieldName
());
String
statusCodeValue
=
"ignore"
;
String
messageValue
=
"ignore"
;
// 打印第三方出参日志 如果feign方法没有IgnoreFeignLogAnnotation注解,全部打日志,但是由于statusCodeValue = "ignore",是不是触发日志告警的
LogIgnoreFeign
logIgnore
=
currentMethod
.
getAnnotation
(
LogIgnoreFeign
.
class
);
if
(
logIgnore
!=
null
)
{
JSONObject
json
=
JSON
.
parseObject
(
JSON
.
toJSONString
(
result
));
statusCodeValue
=
json
.
getString
(
logIgnore
.
statusCodeFieldName
());
messageValue
=
json
.
getString
(
logIgnore
.
messageFieldName
());
if
(!
this
.
printFeignResponseBodyLog
&&
!
logIgnore
.
printLog
())
{
//todo 当排除了这个状态码不打印响应的具体内容只会打印状态码和状态描述信息
String
[]
excludeStatusCodes
=
logIgnore
.
excludeStatusCodes
();
//当排除了这个状态码不打印响应的具体内容只会打印状态码和状态描述信息
if
(!
StringUtils
.
isEmpty
(
statusCodeValue
)
&&
this
.
containStatusCode
(
excludeStatusCodes
,
statusCodeValue
))
{
logReult
=
result
.
getClass
().
newInstance
();
org
.
apache
.
commons
.
beanutils
.
BeanUtils
.
setProperty
(
logReult
,
logIgnore
.
statusCodeFieldName
(),
statusCodeValue
);
...
...
@@ -76,7 +79,7 @@ public class LogIgnoreFeignAspect {
}
}
}
ThirdPartyLog
.
infoConvertJson
(
LogThreadLocal
.
getTrackingNo
(),
SDKCommonBaseContextWare
.
getAppName
()
,
start
,
System
.
currentTimeMillis
(),
ThirdPartyLog
.
infoConvertJson
(
statusCodeValue
,
messageValue
,
start
,
System
.
currentTimeMillis
(),
thirdPartLogVo
.
getUri
(),
thirdPartLogVo
.
getRequestBody
(),
logReult
);
}
}
catch
(
Exception
e
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment