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
93255d30
Commit
93255d30
authored
Mar 22, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
不记录系统日志
parent
ce382c60
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
26 deletions
+28
-26
BaseRequestAspect.java
...ain/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
+21
-15
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+7
-11
No files found.
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/BaseRequestAspect.java
View file @
93255d30
...
...
@@ -164,17 +164,18 @@ public class BaseRequestAspect {
/**
* 记录请求日志
*
* @param joinPoint
* @param tag
* @param url
* @param requestBody
* @param logFlag
* @return
*/
protected
long
requestLog
(
String
tag
,
boolean
logFlag
,
ProceedingJoinPoint
joinPoint
)
{
protected
long
requestLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
String
requestBody
,
boolean
logFlag
)
{
long
start
=
System
.
currentTimeMillis
();
try
{
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
()))));
Log
.
info
(
cls
,
" %s [ %s ] request: %s"
,
tag
,
url
,
this
.
getMaxString
(
requestBody
));
}
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
...
...
@@ -185,17 +186,20 @@ public class BaseRequestAspect {
/**
* 保存日志
*
* @param joinPoint
* @param cls
* @param tag
* @param url
* @param logFlag
* @param start
* @param result
* @param resultEx
* @param
start
* @param
log
*/
protected
void
responseLog
(
LogVo
log
,
String
tag
,
String
url
,
boolean
logFlag
,
ProceedingJoinPoint
joinPoint
,
long
start
,
Object
result
,
Exception
resultEx
)
{
protected
void
responseLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
boolean
logFlag
,
long
start
,
Object
result
,
Exception
resultEx
,
LogVo
log
)
{
try
{
long
time
=
System
.
currentTimeMillis
()
-
start
;
boolean
isLogDisplay
=
(
logFlag
&&
logCommon
)
||
resultEx
!=
null
;
boolean
isLogDatabase
=
log
!=
null
||
resultEx
!=
null
;
String
name
=
joinPoint
.
getSignature
().
getName
();
// 处理结果
ResponseResult
responseResult
=
responseDefault
;
if
(
result
instanceof
ResponseResult
)
{
...
...
@@ -208,12 +212,14 @@ public class BaseRequestAspect {
responseResult
=
ExceptionHelper
.
getError
(
resultEx
);
resultEx
.
printStackTrace
();
}
if
(
isLogDisplay
)
{
Log
.
error
(
joinPoint
.
getSignature
().
getDeclaringType
(),
resultEx
,
"%s [ %s ] time %d ms, result: %s"
,
tag
,
name
,
time
,
getMaxString
(
JsonHelper
.
serialize
(
responseResult
)));
}
if
(
isLogDatabase
)
{
logLocal
.
result
(
log
,
name
,
responseResult
.
getCode
(),
JsonHelper
.
serialize
(
responseResult
));
if
(
isLogDisplay
||
isLogDatabase
)
{
String
json
=
JsonHelper
.
serialize
(
responseResult
);
if
(
isLogDisplay
)
{
Log
.
error
(
cls
,
resultEx
,
"%s [ %s ] time %d ms, result: %s"
,
tag
,
url
,
time
,
getMaxString
(
json
));
}
if
(
isLogDatabase
)
{
logLocal
.
result
(
log
,
tag
,
responseResult
.
getCode
(),
json
);
}
}
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
93255d30
...
...
@@ -70,19 +70,15 @@ public class WebAspect extends BaseRequestAspect {
result
=
executeMethod
(
joinPoint
);
return
result
;
}
Class
declaringType
=
joinPoint
.
getSignature
().
getDeclaringType
();
String
url
=
getMethodUrl
(
joinPoint
);
String
requestBody
=
getRequestBody
(
joinPoint
);
LogVo
log
=
null
;
boolean
clear
=
requestLogInit
();
long
start
=
System
.
currentTimeMillis
();
String
url
=
getMethodUrl
(
joinPoint
);
long
start
=
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
if
(
clear
)
{
log
=
startLog
(
TAG
,
url
,
getRequestBody
(
joinPoint
));
clear
=
clear
&&
log
!=
null
;
log
=
startLog
(
TAG
,
url
,
requestBody
);
}
if
(
clear
)
{
Log
.
threadBegin
();
start
=
requestLog
(
TAG
,
clear
,
joinPoint
);
}
Exception
ex
=
null
;
boolean
isInit
=
false
;
try
{
...
...
@@ -124,7 +120,7 @@ public class WebAspect extends BaseRequestAspect {
if
(
isInit
)
{
TokenHelper
.
remove
();
}
responseLog
(
log
,
TAG
,
url
,
clear
,
joinPoint
,
start
,
result
,
ex
);
responseLog
(
declaringType
,
TAG
,
url
,
clear
,
start
,
result
,
ex
,
log
);
}
}
...
...
@@ -134,7 +130,7 @@ public class WebAspect extends BaseRequestAspect {
* @return
*/
private
boolean
isGateWay
()
{
return
this
.
applicationName
.
matches
(
this
.
gateWay
);
return
this
.
applicationName
.
toLowerCase
().
matches
(
this
.
gateWay
);
}
...
...
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