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
0c29ea54
Commit
0c29ea54
authored
Mar 11, 2025
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复异常提醒,从而正确的跟踪异常信息
parent
a33890ee
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
157 additions
and
56 deletions
+157
-56
CloudConfig.java
...se/src/main/java/com/yanzuoguang/util/vo/CloudConfig.java
+14
-3
AspectLogResult.java
...db/src/main/java/com/yanzuoguang/log/AspectLogResult.java
+3
-2
LogBase.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogBase.java
+9
-0
LogFeignBase.java
...il-db/src/main/java/com/yanzuoguang/log/LogFeignBase.java
+16
-3
LogFeignDefault.java
...db/src/main/java/com/yanzuoguang/log/LogFeignDefault.java
+16
-5
LogInfoVo.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogInfoVo.java
+51
-5
LogLocal.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogLocal.java
+24
-31
LogUrlCountVo.java
...l-db/src/main/java/com/yanzuoguang/log/LogUrlCountVo.java
+24
-7
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/vo/CloudConfig.java
View file @
0c29ea54
...
...
@@ -7,7 +7,9 @@ import com.yanzuoguang.util.log.Log;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.stereotype.Component
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.List
;
/**
* 整个模块的所有配置信息
...
...
@@ -39,8 +41,13 @@ public class CloudConfig {
/**
* 1个请求最长时间(毫秒)
*/
@Value
(
"${yzg.log.time.max:30000}"
)
private
int
logTimeMax
;
@Value
(
"${yzg.log.time.max:[0,100,300,1000,5000,30000]}"
)
private
List
<
Integer
>
logTimeMax
=
new
ArrayList
<>();
/**
* 死锁时间
*/
@Value
(
"${yzg.log.time.lockTime:180000}"
)
private
int
lockTime
;
/**
* 1个请求间隔记录时间(毫秒)
*/
...
...
@@ -103,10 +110,14 @@ public class CloudConfig {
return
reqSize
;
}
public
int
getLogTimeMax
()
{
public
List
<
Integer
>
getLogTimeMax
()
{
return
logTimeMax
;
}
public
int
getLockTime
()
{
return
lockTime
;
}
public
int
getLogTimeSplit
()
{
return
logTimeSplit
;
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/AspectLogResult.java
View file @
0c29ea54
...
...
@@ -41,14 +41,15 @@ public class AspectLogResult {
return
;
}
try
{
lo
g
.
setEnd
(
System
.
currentTimeMillis
()
);
long
useTime
=
log
.
getEnd
()
-
log
.
getStart
();
lo
ng
end
=
System
.
currentTimeMillis
(
);
long
useTime
=
end
-
log
.
getStart
();
log
.
setUseTime
((
int
)
useTime
);
if
(
resultEx
!=
null
)
{
log
.
setStatus
(
LogInfoVo
.
STATUS_ERROR
);
}
else
{
log
.
setStatus
(
LogInfoVo
.
STATUS_OK
);
}
log
.
setEnd
(
end
);
ResponseResult
<?>
responseResult
=
getJson
(
resultFrom
,
resultEx
);
String
json
=
JsonHelper
.
serialize
(
responseResult
);
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogBase.java
View file @
0c29ea54
...
...
@@ -6,6 +6,7 @@ import com.yanzuoguang.util.vo.CloudConfig;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
import
java.util.Optional
;
import
java.util.concurrent.LinkedBlockingQueue
;
...
...
@@ -93,6 +94,14 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
return
true
;
}
public
void
notifyNotHandle
(
List
<
LogInfoVo
>
notHandles
)
{
logFeign
.
notifyNotHandle
(
notHandles
);
}
public
void
notifyTodayCount
(
LogCountResult
todayResult
)
{
logFeign
.
notifyTodayCount
(
todayResult
);
}
/**
* 沉睡时间
*
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogFeignBase.java
View file @
0c29ea54
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.vo.ResponseResul
t
;
import
java.util.Lis
t
;
/**
* 调用外置服务保存日志对象
...
...
@@ -13,7 +13,20 @@ public interface LogFeignBase {
* 保存日志对象
*
* @param log 需要保存的日志对象
* @return 日志服务返回结果
*/
ResponseResult
<
String
>
save
(
LogInfoVo
log
);
void
save
(
LogInfoVo
log
);
/**
* 今日处理中的请求
*
* @param notHandles 处理中的请求
*/
void
notifyNotHandle
(
List
<
LogInfoVo
>
notHandles
);
/**
* 通知今日结果
*
* @param todayResult 今日结果
*/
void
notifyTodayCount
(
LogCountResult
todayResult
);
}
yzg-util-db/src/main/java/com/yanzuoguang/log/LogFeignDefault.java
View file @
0c29ea54
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.
vo.ResponseResult
;
import
com.yanzuoguang.util.
base.CollectionString
;
import
org.springframework.stereotype.Component
;
import
java.util.List
;
/**
* 日志默认处理服务
*
...
...
@@ -10,15 +12,24 @@ import org.springframework.stereotype.Component;
*/
@Component
public
class
LogFeignDefault
implements
LogFeignBase
{
/**
* 保存日志对象
*
* @param log 需要保存的日志对象
* @return 日志服务返回结果
*/
@Override
public
ResponseResult
<
String
>
save
(
LogInfoVo
log
)
{
return
ResponseResult
.
result
(
"处理成功"
);
public
void
save
(
LogInfoVo
log
)
{
}
@Override
public
void
notifyNotHandle
(
List
<
LogInfoVo
>
notHandles
)
{
}
@Override
public
void
notifyTodayCount
(
LogCountResult
todayResult
)
{
// 打印日志
String
tag
=
todayResult
.
getTodayTime
()
+
"执行次数:"
;
String
collectionString
=
CollectionString
.
getCollectionString
(
tag
,
todayResult
.
getList
());
System
.
out
.
println
(
collectionString
);
}
}
yzg-util-db/src/main/java/com/yanzuoguang/log/LogInfoVo.java
View file @
0c29ea54
...
...
@@ -49,7 +49,7 @@ public class LogInfoVo extends BaseVo {
* 接口处理状态,是否有异常
*/
@ApiModelProperty
(
notes
=
"执行状态: -1表示执行中,0-表示失败,1表示成功"
,
required
=
true
,
example
=
"0"
)
private
int
status
=
STATUS_WAIT
;
private
volatile
int
status
=
STATUS_WAIT
;
/**
* 开始时间
*/
...
...
@@ -59,12 +59,12 @@ public class LogInfoVo extends BaseVo {
* 结束时间
*/
@ApiModelProperty
(
notes
=
"结束时间: 单位(毫秒)"
)
private
long
end
=
System
.
currentTimeMillis
()
;
private
long
end
=
0
;
/**
* 使用时间
*/
@ApiModelProperty
(
notes
=
"执行耗时: 单位(毫秒)"
,
required
=
true
,
example
=
"20"
)
private
int
useTime
;
private
long
useTime
;
/**
* 创建时间
*/
...
...
@@ -75,6 +75,20 @@ public class LogInfoVo extends BaseVo {
*/
@ApiModelProperty
(
notes
=
"是否记录日志"
)
private
boolean
logFlag
;
/**
* 是否已处理
*/
@ApiModelProperty
(
notes
=
"是否已处理"
)
private
Handle
handle
;
/**
* 判断是否首次处理
*
* @return 返回值
*/
public
synchronized
boolean
isFirstHandle
()
{
return
this
.
handle
==
null
;
}
public
String
getLogId
()
{
return
logId
;
...
...
@@ -156,11 +170,11 @@ public class LogInfoVo extends BaseVo {
this
.
end
=
end
;
}
public
int
getUseTime
()
{
public
long
getUseTime
()
{
return
useTime
;
}
public
void
setUseTime
(
int
useTime
)
{
public
void
setUseTime
(
long
useTime
)
{
this
.
useTime
=
useTime
;
}
...
...
@@ -179,4 +193,36 @@ public class LogInfoVo extends BaseVo {
public
void
setLogFlag
(
boolean
logFlag
)
{
this
.
logFlag
=
logFlag
;
}
public
Handle
getHandle
()
{
return
handle
;
}
public
void
setHandle
(
Handle
handle
)
{
this
.
handle
=
handle
;
}
public
static
class
Handle
{
private
final
int
level
;
private
final
long
useTime
;
private
final
boolean
isLog
;
public
Handle
(
int
level
,
long
useTime
,
boolean
isLog
)
{
this
.
level
=
level
;
this
.
useTime
=
useTime
;
this
.
isLog
=
isLog
;
}
public
int
getLevel
()
{
return
level
;
}
public
long
getUseTime
()
{
return
useTime
;
}
public
boolean
isLog
()
{
return
isLog
;
}
}
}
yzg-util-db/src/main/java/com/yanzuoguang/log/LogLocal.java
View file @
0c29ea54
...
...
@@ -21,25 +21,14 @@ import static com.yanzuoguang.log.LogInfoVo.STATUS_WAIT;
*/
@Component
public
class
LogLocal
implements
ThreadNext
.
Next
,
InitializingBean
{
/**
* 一个请求最多保留60分钟
*/
public
static
final
int
CLEAR_CACHE
=
60
*
60
;
/**
* 超时状态
*/
public
static
final
String
MAX_TIME
=
"MAX_TIME"
;
public
static
final
String
MAX_TIME_NAME
=
"执行超时"
;
/**
* 日志基础
*/
private
final
LogBase
logBase
;
private
final
CloudConfig
cloudConfig
;
private
final
List
<
LogFilter
>
logFilters
;
private
final
LogCountTime
logCountTime
;
/**
* 缓存队列
* 缓存队列
,一个请求最多保留60分钟
*/
public
static
final
int
CLEAR_CACHE
=
60
*
60
;
protected
volatile
MemoryCache
<
Timeout
<
LogInfoVo
>>
cache
=
new
MemoryCache
<>(
CLEAR_CACHE
);
public
LogLocal
(
LogBase
logBase
,
CloudConfig
cloudConfig
,
List
<
LogFilter
>
logFilters
,
LogCountTime
logCountTime
)
{
...
...
@@ -71,27 +60,22 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @param log 日志对象
*/
public
void
result
(
LogInfoVo
log
)
{
if
(
log
==
null
||
StringHelper
.
isEmpty
(
log
.
getLogId
()))
{
// 日志不存在或已处理
if
(
log
==
null
||
StringHelper
.
isEmpty
(
log
.
getLogId
())
||
cache
.
get
(
log
.
getLogId
())
==
null
)
{
return
;
}
Timeout
<
LogInfoVo
>
timeout
;
// 判断是否延时结果
boolean
isMaxTime
=
log
.
getStatus
()
==
STATUS_WAIT
;
if
(
isMaxTime
)
{
timeout
=
cache
.
get
(
log
.
getLogId
());
}
else
{
timeout
=
cache
.
remove
(
log
.
getLogId
());
// 获取是否已处理
boolean
isWait
=
log
.
getStatus
()
==
STATUS_WAIT
;
if
(!
isWait
)
{
cache
.
remove
(
log
.
getLogId
());
}
// 日志请求不记录,防止死循环递归
boolean
isLog
=
isLog
(
log
.
getTag
(),
log
.
getUrl
());
// 全路径
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
// 执行时间
long
time
=
System
.
currentTimeMillis
()
-
log
.
getStart
();
// 记录请求时间
logCountTime
.
finish
(
log
);
logBase
.
addLog
(
log
);
// 日志详情请求不记录,防止死循环递归
boolean
isLog
=
isLog
(
log
.
getTag
(),
log
.
getUrl
());
if
(
isLog
)
{
logBase
.
addLog
(
log
);
}
}
...
...
@@ -125,16 +109,25 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/
@Override
public
boolean
next
()
{
// 正在处理的任务
List
<
LogInfoVo
>
notHandles
=
new
ArrayList
<>();
Collection
<
Timeout
<
LogInfoVo
>>
values
=
cache
.
getValues
();
for
(
Timeout
<
LogInfoVo
>
timeout
:
values
)
{
if
(
timeout
==
null
)
{
continue
;
}
LogInfoVo
log
=
timeout
.
getData
();
boolean
isLog
=
isLog
(
log
.
getTag
(),
log
.
getUrl
());
if
(
isLog
)
{
notHandles
.
add
(
log
);
}
// 判断是否达到超时时间
if
(
timeout
.
isMaxTime
(
this
.
cloudConfig
.
getLo
gTimeMax
(),
this
.
cloudConfig
.
getLogTimeSplit
()))
{
this
.
result
(
timeout
.
getData
()
);
if
(
timeout
.
isMaxTime
(
this
.
cloudConfig
.
getLo
ckTime
(),
this
.
cloudConfig
.
getLogTimeSplit
()))
{
this
.
result
(
log
);
}
}
// 通知正在处理中的任务队列
logBase
.
notifyNotHandle
(
notHandles
);
return
true
;
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogUrlCountVo.java
View file @
0c29ea54
...
...
@@ -10,6 +10,7 @@ public class LogUrlCountVo {
private
final
Object
lockFinish
=
new
Object
();
private
volatile
String
url
;
private
volatile
int
level
;
private
volatile
int
startCount
;
private
volatile
int
endCount
;
private
volatile
int
errorCount
;
...
...
@@ -18,18 +19,13 @@ public class LogUrlCountVo {
private
volatile
long
minTime
=
Long
.
MAX_VALUE
;
private
volatile
long
maxTime
;
public
LogUrlCountVo
(
String
url
)
{
public
LogUrlCountVo
(
String
url
,
int
level
)
{
this
.
url
=
url
;
}
public
void
addStart
()
{
synchronized
(
this
.
lockStart
)
{
this
.
startCount
++;
}
}
public
void
addFinish
(
long
time
,
boolean
isLog
)
{
synchronized
(
lockFinish
)
{
this
.
startCount
++;
this
.
endCount
++;
if
(
isLog
)
{
this
.
errorCount
++;
...
...
@@ -41,6 +37,18 @@ public class LogUrlCountVo {
}
}
public
void
subFinish
(
long
time
,
boolean
isLog
)
{
synchronized
(
lockFinish
)
{
this
.
startCount
--;
this
.
endCount
--;
if
(
isLog
)
{
this
.
errorCount
--;
}
this
.
totalTime
-=
time
;
this
.
avgTime
=
this
.
totalTime
/
this
.
endCount
;
}
}
public
String
getUrl
()
{
return
url
;
}
...
...
@@ -49,6 +57,15 @@ public class LogUrlCountVo {
this
.
url
=
url
;
}
public
int
getLevel
()
{
return
level
;
}
public
void
setLevel
(
int
level
)
{
this
.
level
=
level
;
}
public
int
getStartCount
()
{
return
startCount
;
}
...
...
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