Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
77471e09
Commit
77471e09
authored
Dec 13, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
接口文档的支持
parent
67b01f41
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
16 deletions
+31
-16
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+14
-13
FeignAspect.java
.../src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
+6
-1
MqAspect.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/MqAspect.java
+7
-1
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+4
-1
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
77471e09
...
...
@@ -33,8 +33,8 @@ public class BaseRequestAspect implements ThreadNext.Next {
@Value
(
"${spring.application.name}"
)
protected
String
applicationName
;
@Value
(
"${yzg.logCommon:
tru
e}"
)
protected
boolean
logCommon
=
true
;
@Value
(
"${yzg.logCommon:
fals
e}"
)
protected
boolean
logCommon
;
@Value
(
"${yzg.logAll:false}"
)
protected
boolean
logAll
=
false
;
...
...
@@ -164,9 +164,11 @@ public class BaseRequestAspect implements ThreadNext.Next {
protected
long
requestLog
(
String
tag
,
ProceedingJoinPoint
joinPoint
)
{
long
start
=
System
.
currentTimeMillis
();
try
{
String
name
=
joinPoint
.
getSignature
().
getName
();
Log
.
info
(
joinPoint
.
getSignature
().
getDeclaringType
(),
" %s [ %s ] request: %s"
,
tag
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
getFirstDataParameter
(
joinPoint
.
getArgs
()))));
if
(
logCommon
)
{
String
name
=
joinPoint
.
getSignature
().
getName
();
Log
.
info
(
joinPoint
.
getSignature
().
getDeclaringType
(),
" %s [ %s ] request: %s"
,
tag
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
getFirstDataParameter
(
joinPoint
.
getArgs
()))));
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
}
...
...
@@ -182,7 +184,7 @@ public class BaseRequestAspect implements ThreadNext.Next {
* @param resultEx
* @param start
*/
protected
void
responseLog
(
boolean
clear
,
String
tag
,
String
url
,
ProceedingJoinPoint
joinPoint
,
long
start
,
Object
result
,
Exception
resultEx
)
{
protected
void
responseLog
(
boolean
save
,
boolean
clear
,
String
tag
,
String
url
,
ProceedingJoinPoint
joinPoint
,
long
start
,
Object
result
,
Exception
resultEx
)
{
try
{
String
name
=
joinPoint
.
getSignature
().
getName
();
if
(
StringHelper
.
isEmpty
(
url
))
{
...
...
@@ -214,14 +216,13 @@ public class BaseRequestAspect implements ThreadNext.Next {
}
// 正常请求不记录
if
(!
logAll
&&
responseResult
!=
null
&&
responseResult
.
getCode
()
==
ResultConstants
.
SUCCESS
)
{
return
;
boolean
error
=
resultEx
!=
null
||
responseResult
==
null
||
ResultConstants
.
SUCCESS
.
equals
(
responseResult
.
getCode
());
boolean
logFlag
=
(
logAll
&&
save
)
||
error
;
if
(
logFlag
)
{
LogVo
logVo
=
initLogInterVo
(
url
,
joinPoint
,
responseResult
);
logVo
.
setUseTime
((
int
)
time
);
addLog
(
logVo
);
}
LogVo
logVo
=
initLogInterVo
(
url
,
joinPoint
,
responseResult
);
logVo
.
setUseTime
((
int
)
time
);
addLog
(
logVo
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
View file @
77471e09
...
...
@@ -9,6 +9,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
...
...
@@ -22,6 +23,10 @@ public class FeignAspect extends BaseRequestAspect {
private
static
final
String
TAG
=
FeignAspect
.
class
.
getSimpleName
();
@Value
(
"${yzg.logFeign:false}"
)
private
boolean
logFeign
;
/**
* AOP的表达式
*/
...
...
@@ -62,7 +67,7 @@ public class FeignAspect extends BaseRequestAspect {
ex
=
e
;
throw
e
;
}
finally
{
responseLog
(
clear
,
TAG
,
StringHelper
.
EMPTY
,
joinPoint
,
start
,
result
,
ex
);
responseLog
(
logFeign
,
clear
,
TAG
,
StringHelper
.
EMPTY
,
joinPoint
,
start
,
result
,
ex
);
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/MqAspect.java
View file @
77471e09
...
...
@@ -6,6 +6,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
/**
...
...
@@ -20,6 +21,9 @@ public class MqAspect extends BaseRequestAspect {
private
static
final
String
TAG
=
MqAspect
.
class
.
getSimpleName
();
@Value
(
"${yzg.logMq:false}"
)
private
boolean
logMq
;
/**
* exec aop point aspect
*/
...
...
@@ -48,7 +52,9 @@ public class MqAspect extends BaseRequestAspect {
ex
=
e
;
throw
e
;
}
finally
{
responseLog
(
clear
,
TAG
,
StringHelper
.
EMPTY
,
joinPoint
,
start
,
result
,
ex
);
if
(
logMq
||
ex
!=
null
)
{
responseLog
(
logMq
,
clear
,
TAG
,
StringHelper
.
EMPTY
,
joinPoint
,
start
,
result
,
ex
);
}
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
77471e09
...
...
@@ -36,6 +36,9 @@ public class WebAspect extends BaseRequestAspect {
@Autowired
private
TokenServiceCall
tokenServiceCall
;
@Value
(
"${yzg.logWeb:false}"
)
private
boolean
logWeb
;
@Value
(
"${yzg.gateway:^.*gateway.*$}"
)
private
String
gateWay
;
...
...
@@ -85,7 +88,7 @@ public class WebAspect extends BaseRequestAspect {
tokenFinish
(
flag
);
TokenHelper
.
remove
();
}
responseLog
(
clear
,
TAG
,
HttpAspectUtil
.
getHttpRequestUrl
(),
joinPoint
,
start
,
result
,
ex
);
responseLog
(
logWeb
,
clear
,
TAG
,
HttpAspectUtil
.
getHttpRequestUrl
(),
joinPoint
,
start
,
result
,
ex
);
}
}
...
...
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