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
00b03e8d
Commit
00b03e8d
authored
Mar 19, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
不记录系统日志
parent
d000e9db
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
33 deletions
+43
-33
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+14
-14
FeignAspect.java
.../src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
+2
-2
MqAspect.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/MqAspect.java
+25
-15
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+2
-2
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
00b03e8d
...
...
@@ -51,6 +51,8 @@ public class BaseRequestAspect {
@Autowired
private
LogLocal
logLocal
;
private
ResponseResult
responseDefault
=
new
ResponseResult
();
/**
* 开始记录日志对象
*
...
...
@@ -163,10 +165,11 @@ public class BaseRequestAspect {
* @param joinPoint
* @return
*/
protected
long
requestLog
(
String
tag
,
ProceedingJoinPoint
joinPoint
)
{
protected
long
requestLog
(
String
tag
,
boolean
logFlag
,
ProceedingJoinPoint
joinPoint
)
{
long
start
=
System
.
currentTimeMillis
();
try
{
if
(
logCommon
)
{
boolean
isLog
=
logFlag
&&
logCommon
;
if
(
isLog
)
{
String
name
=
joinPoint
.
getSignature
().
getName
();
Log
.
info
(
joinPoint
.
getSignature
().
getDeclaringType
(),
" %s [ %s ] request: %s"
,
tag
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
getFirstDataParameter
(
joinPoint
.
getArgs
()))));
...
...
@@ -177,8 +180,6 @@ public class BaseRequestAspect {
return
start
;
}
private
ResponseResult
responseDefault
=
new
ResponseResult
();
/**
* 保存日志
*
...
...
@@ -187,8 +188,10 @@ public class BaseRequestAspect {
* @param resultEx
* @param start
*/
protected
void
responseLog
(
LogVo
log
,
boolean
clear
,
String
t
ag
,
ProceedingJoinPoint
joinPoint
,
long
start
,
Object
result
,
Exception
resultEx
)
{
protected
void
responseLog
(
LogVo
log
,
String
tag
,
boolean
logFl
ag
,
ProceedingJoinPoint
joinPoint
,
long
start
,
Object
result
,
Exception
resultEx
)
{
try
{
long
time
=
System
.
currentTimeMillis
()
-
start
;
boolean
isLog
=
(
logFlag
&&
logCommon
)
||
resultEx
!=
null
;
String
name
=
joinPoint
.
getSignature
().
getName
();
// 处理结果
ResponseResult
responseResult
=
responseDefault
;
...
...
@@ -197,23 +200,20 @@ public class BaseRequestAspect {
}
else
if
(
result
!=
null
)
{
responseResult
=
ResponseResult
.
result
(
result
);
}
long
time
=
System
.
currentTimeMillis
()
-
start
;
// 执行时间
if
(
resultEx
!=
null
)
{
responseResult
=
ExceptionHelper
.
getError
(
resultEx
);
Log
.
error
(
joinPoint
.
getSignature
().
getDeclaringType
(),
resultEx
,
"%s [ %s ] time %d ms, result: %s"
,
tag
,
name
,
time
,
getMaxString
(
JsonHelper
.
serialize
(
responseResult
)));
resultEx
.
printStackTrace
();
}
else
if
(
logCommon
)
{
Log
.
info
(
joinPoint
.
getSignature
().
getDeclaringType
(),
"%s [ %s ] time %d ms, result: %s"
,
}
if
(
isLog
)
{
Log
.
error
(
joinPoint
.
getSignature
().
getDeclaringType
(),
resultEx
,
"%s [ %s ] time %d ms, result: %s"
,
tag
,
name
,
time
,
getMaxString
(
JsonHelper
.
serialize
(
responseResult
)));
logLocal
.
result
(
log
,
name
,
responseResult
.
getCode
(),
JsonHelper
.
serialize
(
responseResult
));
}
logLocal
.
result
(
log
,
name
,
responseResult
.
getCode
(),
JsonHelper
.
serialize
(
responseResult
));
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
finally
{
if
(
clear
)
{
if
(
logFlag
)
{
Log
.
threadCommit
();
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/FeignAspect.java
View file @
00b03e8d
...
...
@@ -38,7 +38,7 @@ public class FeignAspect extends BaseRequestAspect {
@Around
(
value
=
"feignAspect()"
)
public
Object
requestFeignAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
boolean
clear
=
requestLogInit
();
long
start
=
requestLog
(
TAG
,
joinPoint
);
long
start
=
requestLog
(
TAG
,
clear
,
joinPoint
);
LogVo
log
=
startLog
(
TAG
,
getMethodUrl
(
joinPoint
),
getRequestBody
(
joinPoint
));
Object
result
=
null
;
Exception
ex
=
null
;
...
...
@@ -63,7 +63,7 @@ public class FeignAspect extends BaseRequestAspect {
ex
=
e
;
throw
e
;
}
finally
{
responseLog
(
log
,
clear
,
TAG
,
joinPoint
,
start
,
result
,
ex
);
responseLog
(
log
,
TAG
,
clear
,
joinPoint
,
start
,
result
,
ex
);
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/MqAspect.java
View file @
00b03e8d
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.mq.plan.YzgMqConsumer
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.LogVo
;
...
...
@@ -8,9 +9,10 @@ import org.aspectj.lang.annotation.Around;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Pointcut
;
import
org.aspectj.lang.reflect.MethodSignature
;
import
org.springframework.amqp.core.Message
;
import
org.springframework.amqp.rabbit.annotation.RabbitListener
;
import
org.springframework.stereotype.Component
;
import
java.lang.annotation.Annotation
;
import
java.lang.reflect.Method
;
/**
...
...
@@ -41,13 +43,15 @@ public class MqAspect extends BaseRequestAspect {
@Around
(
value
=
"mqAspect()"
)
public
Object
requestWebAround
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
boolean
clear
=
isRabbit
(
joinPoint
);
LogVo
log
=
null
;
long
start
=
System
.
currentTimeMillis
();
if
(
clear
)
{
Log
.
threadBegin
();
start
=
requestLog
(
TAG
,
clear
,
joinPoint
);
log
=
startLog
(
TAG
,
getMethodUrl
(
joinPoint
),
getRequestBody
(
joinPoint
));
}
else
{
clear
=
requestLogInit
();
}
long
start
=
requestLog
(
TAG
,
joinPoint
);
LogVo
log
=
startLog
(
TAG
,
getMethodUrl
(
joinPoint
),
getRequestBody
(
joinPoint
));
Object
result
=
null
;
Exception
ex
=
null
;
try
{
...
...
@@ -59,26 +63,32 @@ public class MqAspect extends BaseRequestAspect {
ex
=
e
;
throw
e
;
}
finally
{
responseLog
(
log
,
clear
,
TAG
,
joinPoint
,
start
,
result
,
ex
);
responseLog
(
log
,
TAG
,
clear
,
joinPoint
,
start
,
result
,
ex
);
}
}
private
boolean
isRabbit
(
ProceedingJoinPoint
joinPoint
)
{
if
(
joinPoint
.
getSignature
()
instanceof
MethodSignature
)
{
MethodSignature
methodSignature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
targetMethod
=
methodSignature
.
getMethod
();
if
(
"YzgMqConsumer"
.
equals
(
targetMethod
.
getDeclaringClass
().
getSimpleName
()))
{
return
false
;
boolean
ret
=
false
;
if
(!(
joinPoint
.
getSignature
()
instanceof
MethodSignature
))
{
return
false
;
}
MethodSignature
methodSignature
=
(
MethodSignature
)
joinPoint
.
getSignature
();
Method
targetMethod
=
methodSignature
.
getMethod
();
if
(
YzgMqConsumer
.
class
.
equals
(
targetMethod
.
getDeclaringClass
()))
{
ret
=
false
;
}
else
{
RabbitListener
annotation
=
targetMethod
.
getAnnotation
(
RabbitListener
.
class
);
if
(
annotation
!=
null
)
{
ret
=
true
;
}
Annotation
[]
annotations
=
targetMethod
.
getAnnotations
();
for
(
Annotation
annotation
:
annotations
)
{
if
(
annotation
.
annotationType
()
!=
null
&&
"RabbitListener"
.
equals
(
annotation
.
annotationType
().
getSimpleName
()))
{
return
true
;
if
(!
ret
)
{
Message
message
=
getMessage
(
joinPoint
.
getArgs
());
if
(
message
!=
null
)
{
ret
=
true
;
}
}
}
return
false
;
return
ret
;
}
private
Object
executeMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
00b03e8d
...
...
@@ -72,7 +72,7 @@ public class WebAspect extends BaseRequestAspect {
}
boolean
clear
=
requestLogInit
();
// 用户数据库记录
long
start
=
requestLog
(
TAG
,
joinPoint
);
long
start
=
requestLog
(
TAG
,
clear
,
joinPoint
);
LogVo
log
=
startLog
(
TAG
,
HttpAspectUtil
.
getHttpRequestUrl
(),
getRequestBody
(
joinPoint
));
Exception
ex
=
null
;
boolean
isInit
=
false
;
...
...
@@ -115,7 +115,7 @@ public class WebAspect extends BaseRequestAspect {
if
(
isInit
)
{
TokenHelper
.
remove
();
}
responseLog
(
log
,
clear
,
TAG
,
joinPoint
,
start
,
result
,
ex
);
responseLog
(
log
,
TAG
,
clear
,
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