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
f451bbd9
Commit
f451bbd9
authored
Aug 08, 2019
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
常规BUG的修改
parent
bdb5ce86
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
59 additions
and
12 deletions
+59
-12
Log.java
...util-base/src/main/java/com/yanzuoguang/util/log/Log.java
+15
-4
LogVo.java
...til-base/src/main/java/com/yanzuoguang/util/vo/LogVo.java
+13
-0
WebAspect.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
+31
-8
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/log/Log.java
View file @
f451bbd9
...
...
@@ -107,23 +107,34 @@ public class Log {
/**
* 当前线程特殊处理异常,一旦调用必须调用 threadCommit 函数
*/
public
static
void
threadBegin
()
{
public
static
LogDate
threadBegin
()
{
// 获取当前线程编号
String
threadId
=
getThreadId
();
LogDate
logDate
=
new
LogDate
();
logDate
.
clear
();
threadCache
.
put
(
threadId
,
logDate
);
return
logDate
;
}
// System.out.println(threadId + " threadBegin");
/**
* 当前县城日志对象
*
* @return
*/
public
static
LogDate
threadCurrent
()
{
String
threadId
=
getThreadId
();
LogDate
log
=
threadCache
.
containsKey
(
threadId
)
?
threadCache
.
get
(
threadId
)
:
null
;
return
log
;
}
/**
* 当前线程结束处理特殊异常
*/
public
static
void
threadCommit
()
{
public
static
LogDate
threadCommit
()
{
String
threadId
=
getThreadId
();
LogDate
log
=
threadCurrent
();
threadCache
.
remove
(
threadId
);
// System.out.println(threadId + " threadCommit")
;
return
log
;
}
/**
...
...
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/LogVo.java
View file @
f451bbd9
...
...
@@ -38,6 +38,11 @@ public class LogVo extends BaseVo {
*/
private
int
status
;
/**
* 使用时间
*/
private
int
useTime
;
/**
* 创建时间
*/
...
...
@@ -91,6 +96,14 @@ public class LogVo extends BaseVo {
this
.
status
=
status
;
}
public
int
getUseTime
()
{
return
useTime
;
}
public
void
setUseTime
(
int
useTime
)
{
this
.
useTime
=
useTime
;
}
public
String
getCreateDate
()
{
return
createDate
;
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/WebAspect.java
View file @
f451bbd9
...
...
@@ -37,14 +37,15 @@ import java.lang.reflect.Type;
@Component
public
class
WebAspect
extends
BaseRequestAspect
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
BaseRequestAspect
.
class
);
@Autowired
private
TokenServiceCall
tokenServiceCall
;
@Value
(
"${yzg.reqUrl:order,check,use}"
)
private
String
reqUrl
;
@Value
(
"${yzg.reqSize:5000}"
)
private
int
reqSize
;
/**
* exec aop point aspect
*/
...
...
@@ -66,8 +67,9 @@ public class WebAspect extends BaseRequestAspect {
long
start
=
System
.
currentTimeMillis
();
String
name
=
joinPoint
.
getSignature
().
getName
();
Ref
<
Boolean
>
flag
=
new
Ref
<>(
false
);
Exception
ex
=
null
;
try
{
logger
.
info
(
"[ {} ] request params is {}"
,
name
,
joinPoint
.
getArgs
(
));
Log
.
info
(
WebAspect
.
class
,
"[ %s ] request params is: %s"
,
name
,
this
.
getMaxString
(
JsonHelper
.
serialize
(
joinPoint
.
getArgs
())
));
tokenServiceCall
.
tokenInit
();
Object
result
=
executeMethod
(
joinPoint
,
name
);
...
...
@@ -78,12 +80,10 @@ public class WebAspect extends BaseRequestAspect {
}
long
end
=
System
.
currentTimeMillis
();
logger
.
info
(
"[ {} ] time ({})ms, result is {}"
,
name
,
(
end
-
start
),
responseResult
);
tokenFinish
(
flag
);
return
result
;
}
catch
(
Exception
e
)
{
long
end
=
System
.
currentTimeMillis
();
logger
.
error
(
"[ {} ] time ({})ms, is error {}"
,
name
,
(
end
-
start
),
e
);
ex
=
e
;
responseResult
=
ExceptionHelper
.
getError
(
e
);
if
(
getReturnType
(
joinPoint
).
getTypeName
().
indexOf
(
ResponseResult
.
class
.
getName
())
>
-
1
)
{
return
responseResult
;
...
...
@@ -92,9 +92,31 @@ public class WebAspect extends BaseRequestAspect {
}
}
finally
{
tokenFinish
(
flag
);
long
time
=
System
.
currentTimeMillis
()
-
start
;
if
(
ex
!=
null
)
{
Log
.
error
(
WebAspect
.
class
,
"[ %s ] time %d ms, error: %s"
,
name
,
time
,
getMaxString
(
ex
.
getMessage
()));
}
else
{
Log
.
info
(
WebAspect
.
class
,
"[ %s ] time %d ms, result is: %s"
,
name
,
time
,
getMaxString
(
JsonHelper
.
serialize
(
responseResult
)));
}
Log
.
threadCommit
();
saveInterLogs
(
joinPoint
,
responseResult
);
saveInterLogs
(
joinPoint
,
responseResult
,
time
);
}
}
/**
* 获取JSON,当Json过长时,截断
*
* @param paraJson
* @return
*/
private
String
getMaxString
(
String
paraJson
)
{
if
(
paraJson
!=
null
&&
paraJson
.
length
()
>
reqSize
)
{
paraJson
=
paraJson
.
substring
(
0
,
reqSize
);
}
return
paraJson
;
}
/**
...
...
@@ -196,7 +218,7 @@ public class WebAspect extends BaseRequestAspect {
* @param joinPoint 请求参数
* @param responseResult 返回参数
*/
private
void
saveInterLogs
(
ProceedingJoinPoint
joinPoint
,
ResponseResult
responseResult
)
{
private
void
saveInterLogs
(
ProceedingJoinPoint
joinPoint
,
ResponseResult
responseResult
,
long
time
)
{
// 日志请求不记录,防止死循环递归
if
(
applicationName
.
indexOf
(
CloudContans
.
LOG_MODULE
)
>=
0
)
{
return
;
...
...
@@ -208,6 +230,7 @@ public class WebAspect extends BaseRequestAspect {
return
;
}
LogVo
logVo
=
initLogInterVo
(
HttpAspectUtil
.
getHttpRequestUrl
(),
joinPoint
,
responseResult
);
logVo
.
setUseTime
((
int
)
time
);
addLog
(
logVo
);
}
}
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