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
beb10a57
Commit
beb10a57
authored
Mar 10, 2025
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复异常提醒,从而正确的跟踪异常信息
parent
c51570bf
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
100 deletions
+47
-100
LogCountTime.java
...il-db/src/main/java/com/yanzuoguang/log/LogCountTime.java
+44
-32
LogLocal.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogLocal.java
+3
-14
LogPrint.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogPrint.java
+0
-54
No files found.
yzg-util-db/src/main/java/com/yanzuoguang/log/LogCountTime.java
View file @
beb10a57
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.cache.MemoryCache
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.Collections
;
import
java.util.Comparator
;
/**
* 日志时间
*
* @author 颜佐光
*/
@Component
public
class
LogCountTime
{
public
class
LogCountTime
implements
ThreadNext
.
Next
,
InitializingBean
{
private
static
final
String
URL_PARA_START
=
"?"
;
private
final
LogConfig
logConfig
;
/**
* 今日缓存,超过时间会自动清空
*/
...
...
@@ -23,28 +29,24 @@ public class LogCountTime {
* 今日日期
*/
private
String
today
;
/**
* 今日时间
*/
private
String
todayTime
;
/**
* 获取日志结果
*
* @return 今日日志结果
*/
public
LogCountResult
getTodayResul
t
()
{
return
new
LogCountResult
(
todayTime
,
todayMemoryCache
.
getValues
()
);
public
LogCountTime
(
LogConfig
logConfig
)
{
this
.
logConfig
=
logConfig
;
}
@Override
public
void
afterPropertiesSe
t
()
{
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
}
private
void
initToday
()
{
String
today
=
DateHelper
.
getToday
();
if
(!
StringHelper
.
compare
(
this
.
today
,
today
))
{
synchronized
(
todayMemoryCache
)
{
synchronized
(
this
.
todayMemoryCache
)
{
this
.
next
();
if
(!
StringHelper
.
compare
(
this
.
today
,
today
))
{
todayMemoryCache
.
clear
();
t
his
.
t
odayMemoryCache
.
clear
();
this
.
today
=
today
;
this
.
todayTime
=
DateHelper
.
getNow
();
}
}
}
...
...
@@ -62,8 +64,7 @@ public class LogCountTime {
String
key
;
if
(
urlFrom
.
contains
(
URL_PARA_START
))
{
key
=
urlFrom
.
substring
(
0
,
urlFrom
.
indexOf
(
URL_PARA_START
));
}
else
{
}
else
{
key
=
urlFrom
;
}
// 缓存中获取对象
...
...
@@ -84,24 +85,35 @@ public class LogCountTime {
}
/**
*
开始记录日志
*
结束
*
* @param
url 请求地址
* @param
log 日志信息
*/
public
void
start
(
String
url
)
{
LogUrlCountVo
count
=
getCount
(
url
);
public
void
finish
(
LogInfoVo
log
)
{
LogUrlCountVo
count
=
getCount
(
log
.
getUrl
()
);
count
.
addStart
();
count
.
addFinish
(
log
.
getUseTime
(),
log
.
getStatus
()
==
LogInfoVo
.
STATUS_ERROR
);
}
/**
* 结束
*
* @param url 请求地址
* @param time 执行时间
* @param isError 是否错误
*/
public
void
finish
(
String
url
,
long
time
,
boolean
isError
)
{
LogUrlCountVo
count
=
getCount
(
url
);
count
.
addFinish
(
time
,
isError
);
@Override
public
boolean
next
()
{
LogCountResult
todayResult
=
new
LogCountResult
(
this
.
today
,
todayMemoryCache
.
getValues
());
if
(
todayResult
.
getList
().
isEmpty
())
{
return
true
;
}
// 按照使用总时间升序排序
todayResult
.
getList
().
sort
(
Comparator
.
comparingLong
(
LogUrlCountVo:
:
getTotalTime
));
// 逆转排序
Collections
.
reverse
(
todayResult
.
getList
());
// 打印日志
String
tag
=
todayResult
.
getTodayTime
()
+
"执行次数:"
;
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
tag
,
todayResult
.
getList
()));
// 下次继续执行
return
true
;
}
@Override
public
int
getNextTime
()
{
return
logConfig
.
getLogCountTime
();
}
}
yzg-util-db/src/main/java/com/yanzuoguang/log/LogLocal.java
View file @
beb10a57
...
...
@@ -69,25 +69,17 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @param log 日志对象
*/
public
void
result
(
LogInfoVo
log
)
{
if
(
log
==
null
)
{
if
(
log
==
null
||
StringHelper
.
isEmpty
(
log
.
getLogId
())
)
{
return
;
}
// 日志请求不记录,防止死循环递归
boolean
isLog
=
isLog
(
log
.
getTag
(),
log
.
getUrl
());
this
.
resultWrite
(
log
);
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
logCountTime
.
start
(
fullUrl
);
// 全路径
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
// 执行时间
long
time
=
System
.
currentTimeMillis
()
-
log
.
getStart
();
// 记录请求时间
logCountTime
.
finish
(
fullUrl
,
time
,
isError
);
if
(
log
==
null
||
StringHelper
.
isEmpty
(
log
.
getLogId
()))
{
return
;
}
logCountTime
.
finish
(
log
);
Timeout
<
LogInfoVo
>
timeout
;
// 判断是否延时结果
boolean
isMaxTime
=
StringHelper
.
compare
(
status
,
MAX_TIME
);
...
...
@@ -96,10 +88,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
}
else
{
timeout
=
cache
.
remove
(
log
.
getLogId
());
}
if
(
write
)
{
logBase
.
addLog
(
log
);
}
logBase
.
addLog
(
log
);
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogPrint.java
deleted
100644 → 0
View file @
c51570bf
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.base.CollectionString
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.Collections
;
import
java.util.Comparator
;
/**
* 将请求次数日志输出
*
* @author 颜佐光
*/
@Component
public
class
LogPrint
implements
ThreadNext
.
Next
,
InitializingBean
{
private
final
LogConfig
logConfig
;
private
final
LogCountTime
logCountTime
;
public
LogPrint
(
LogConfig
logConfig
,
LogCountTime
logCountTime
)
{
this
.
logConfig
=
logConfig
;
this
.
logCountTime
=
logCountTime
;
}
@Override
public
void
afterPropertiesSet
()
{
ThreadNext
.
start
(
this
,
"aspectLogTime"
);
}
@Override
public
boolean
next
()
{
LogCountResult
todayResult
=
logCountTime
.
getTodayResult
();
if
(
todayResult
.
getList
().
isEmpty
())
{
return
true
;
}
// 按照使用总时间升序排序
todayResult
.
getList
().
sort
(
Comparator
.
comparingLong
(
LogUrlCountVo:
:
getTotalTime
));
// 逆转排序
Collections
.
reverse
(
todayResult
.
getList
());
// 打印日志
String
tag
=
"从"
+
todayResult
.
getTodayTime
()
+
"时执行次数:"
;
System
.
out
.
println
(
CollectionString
.
getCollectionString
(
tag
,
todayResult
.
getList
()));
// 下次继续执行
return
true
;
}
@Override
public
int
getNextTime
()
{
return
logConfig
.
getLogCountTime
();
}
}
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