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
557d5ee1
Commit
557d5ee1
authored
Mar 10, 2025
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复异常提醒,从而正确的跟踪异常信息
parent
77db7d8f
Changes
23
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
225 additions
and
151 deletions
+225
-151
Log.java
...util-base/src/main/java/com/yanzuoguang/util/log/Log.java
+6
-8
CloudConfig.java
...se/src/main/java/com/yanzuoguang/util/vo/CloudConfig.java
+3
-3
AspectFeign.java
.../src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
+5
-5
AspectLogBody.java
...rc/main/java/com/yanzuoguang/cloud/aop/AspectLogBody.java
+1
-37
AspectMq.java
...oud/src/main/java/com/yanzuoguang/cloud/aop/AspectMq.java
+8
-8
AspectWeb.java
...ud/src/main/java/com/yanzuoguang/cloud/aop/AspectWeb.java
+6
-6
YzgFileConfig.java
...c/main/java/com/yanzuoguang/cloud/file/YzgFileConfig.java
+1
-1
TestTimeout.java
yzg-util-cloud/src/test/java/TestTimeout.java
+1
-1
AspectLogResult.java
...db/src/main/java/com/yanzuoguang/log/AspectLogResult.java
+10
-18
AspectLogStart.java
...-db/src/main/java/com/yanzuoguang/log/AspectLogStart.java
+82
-0
LogBase.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogBase.java
+7
-10
LogFeign.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogFeign.java
+1
-3
LogFeignBase.java
...il-db/src/main/java/com/yanzuoguang/log/LogFeignBase.java
+1
-2
LogFeignDefault.java
...db/src/main/java/com/yanzuoguang/log/LogFeignDefault.java
+1
-2
LogFilter.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogFilter.java
+1
-1
LogFilterDefault.java
...b/src/main/java/com/yanzuoguang/log/LogFilterDefault.java
+1
-1
LogInfoVo.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogInfoVo.java
+19
-0
LogLocal.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogLocal.java
+15
-27
LogString.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogString.java
+50
-0
LogVo.java
yzg-util-db/src/main/java/com/yanzuoguang/log/LogVo.java
+3
-15
Timeout.java
yzg-util-db/src/main/java/com/yanzuoguang/log/Timeout.java
+1
-1
YzgExcelService.java
...main/java/com/yanzuoguang/cloud/file/YzgExcelService.java
+1
-1
YzgFileServiceImpl.java
...n/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
+1
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/log/Log.java
View file @
557d5ee1
...
...
@@ -43,7 +43,7 @@ public class Log {
* @param ex 错误信息
*/
public
static
void
error
(
Class
<?>
cls
,
Throwable
ex
)
{
ExceptionHelper
.
PrintError
(
cls
,
ex
);
ExceptionHelper
.
PrintError
(
cls
,
ex
);
add
(
new
LogInfo
(
cls
,
new
Date
(),
ex
!=
null
,
ex
,
StringHelper
.
EMPTY
));
}
...
...
@@ -55,7 +55,7 @@ public class Log {
* @param args 错误消息
*/
public
static
void
error
(
Class
<?>
cls
,
Throwable
ex
,
String
msg
,
Object
...
args
)
{
ExceptionHelper
.
PrintError
(
cls
,
ex
);
ExceptionHelper
.
PrintError
(
cls
,
ex
);
String
toMsg
=
getFormat
(
msg
,
args
);
add
(
new
LogInfo
(
cls
,
new
Date
(),
ex
!=
null
,
ex
,
toMsg
));
}
...
...
@@ -120,6 +120,8 @@ public class Log {
/**
* 当前线程特殊处理异常,一旦调用必须调用 threadCommit 函数
*
* @return 返回记录日志得对象
*/
public
static
LogDate
threadBegin
()
{
// 获取当前线程编号
...
...
@@ -141,15 +143,11 @@ public class Log {
}
/**
* 当前线程结束处理特殊异常
*
* @return 返回日志信息
* 当前线程结束处理日志
*/
public
static
LogDate
threadCommit
()
{
public
static
void
threadCommit
()
{
String
threadId
=
getThreadId
();
LogDate
log
=
threadCurrent
();
threadCache
.
remove
(
threadId
);
return
log
;
}
/**
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud
/CloudConfig.java
→
yzg-util-
base/src/main/java/com/yanzuoguang/util/vo
/CloudConfig.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
;
package
com
.
yanzuoguang
.
util
.
vo
;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.helper.DateHelper
;
...
...
@@ -141,7 +141,7 @@ public class CloudConfig {
/**
* 获取行记的显示的图片
*
* @return
* @return
临时目录
*/
public
String
getTempFolder
(
String
folder
,
Date
date
)
{
return
String
.
format
(
"%s/%s/%s/%s"
,
...
...
@@ -155,7 +155,7 @@ public class CloudConfig {
/**
* 是否属于网关服务,网关服务不进行监控
*
* @return
* @return
是否属于网关
*/
public
boolean
isGateWay
()
{
return
this
.
applicationName
.
toLowerCase
().
matches
(
this
.
gateWay
);
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectFeign.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.cloud.aop.log.AspectLogResult
;
import
com.yanzuoguang.cloud.aop.log.AspectLogStart
;
import
com.yanzuoguang.log.AspectLogResult
;
import
com.yanzuoguang.log.AspectLogStart
;
import
com.yanzuoguang.log.LogInfoVo
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.vo.LogVo
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
...
...
@@ -56,7 +56,7 @@ public class AspectFeign {
Object
requestBody
=
aspectLogBody
.
getRequestBody
(
joinPoint
);
boolean
clear
=
aspectLogStart
.
requestLogInit
();
LogVo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Log
Info
Vo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Object
result
=
null
;
Exception
ex
=
null
;
...
...
@@ -76,7 +76,7 @@ public class AspectFeign {
ex
=
e
;
throw
e
;
}
finally
{
aspectLogResult
.
responseLog
(
declaringType
,
TAG
,
url
,
clear
,
requestBody
,
result
,
ex
,
log
);
aspectLogResult
.
responseLog
(
log
,
result
,
ex
);
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectLogBody.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.rabbitmq.client.Channel
;
import
com.yanzuoguang.
cloud
.CloudConfig
;
import
com.yanzuoguang.
util.vo
.CloudConfig
;
import
com.yanzuoguang.cloud.vo.YzgFileUploadReqVo
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
org.aspectj.lang.ProceedingJoinPoint
;
...
...
@@ -24,42 +24,6 @@ import java.util.List;
@Component
public
class
AspectLogBody
{
private
final
CloudConfig
cloudConfig
;
public
AspectLogBody
(
CloudConfig
cloudConfig
)
{
this
.
cloudConfig
=
cloudConfig
;
}
/**
* 获取JSON,当Json过长时,截断
*
* @param paraJson 长json字符串
* @return 短json字符串
*/
public
String
getMaxString
(
String
paraJson
)
{
if
(
paraJson
!=
null
&&
paraJson
.
length
()
>
this
.
cloudConfig
.
getReqSize
())
{
paraJson
=
paraJson
.
substring
(
0
,
this
.
cloudConfig
.
getReqSize
());
}
return
paraJson
;
}
/**
* 获取内容转换为字符串
*
* @param body 内容
* @return 字符串
*/
public
String
getBodyString
(
Object
body
)
{
String
ret
;
if
(
body
instanceof
String
)
{
ret
=
getMaxString
((
String
)
body
);
}
else
{
ret
=
getMaxString
(
JsonHelper
.
serialize
(
body
));
}
return
ret
;
}
/**
* 获取请求内容
*
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectMq.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.cloud.aop.log.AspectLogResult
;
import
com.yanzuoguang.cloud.aop.log.AspectLogStart
;
import
com.yanzuoguang.log.AspectLogResult
;
import
com.yanzuoguang.log.AspectLogStart
;
import
com.yanzuoguang.log.LogInfoVo
;
import
com.yanzuoguang.mq.service.MessageLogService
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.vo.LogVo
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.annotation.Around
;
import
org.aspectj.lang.annotation.Aspect
;
...
...
@@ -64,7 +64,7 @@ public class AspectMq {
boolean
clear
=
true
;
aspectLogStart
.
requestLogInit
();
LogVo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Log
Info
Vo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Object
result
=
null
;
Exception
ex
=
null
;
try
{
...
...
@@ -77,16 +77,16 @@ public class AspectMq {
throw
e
;
}
finally
{
logService
.
logCurrentRemove
();
aspectLogResult
.
responseLog
(
declaringType
,
TAG
,
url
,
clear
,
requestBody
,
result
,
ex
,
log
);
aspectLogResult
.
responseLog
(
log
,
result
,
ex
);
}
}
/**
* 执行函数
*
* @param joinPoint
* @return
* @throws Throwable
* @param joinPoint
执行函数
* @return
返回值
* @throws Throwable
是否抛出异常
*/
private
Object
executeMethod
(
ProceedingJoinPoint
joinPoint
)
throws
Throwable
{
return
joinPoint
.
proceed
();
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/aop/AspectWeb.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.log.AspectLogResult
;
import
com.yanzuoguang.cloud.aop.log.AspectLogStart
;
import
com.yanzuoguang.cloud.service.TokenServiceCall
;
import
com.yanzuoguang.log.AspectLogResult
;
import
com.yanzuoguang.log.AspectLogStart
;
import
com.yanzuoguang.log.LogInfoVo
;
import
com.yanzuoguang.token.TokenHelper
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.TypeHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.
LogVo
;
import
com.yanzuoguang.util.vo.
CloudConfig
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
org.aspectj.lang.ProceedingJoinPoint
;
import
org.aspectj.lang.Signature
;
...
...
@@ -90,7 +90,7 @@ public class AspectWeb {
}
Object
requestBody
=
aspectLogBody
.
getRequestBody
(
joinPoint
);
boolean
clear
=
aspectLogStart
.
requestLogInit
();
LogVo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Log
Info
Vo
log
=
aspectLogStart
.
requestLog
(
declaringType
,
TAG
,
url
,
requestBody
,
clear
);
Exception
ex
=
null
;
boolean
isInit
=
false
;
...
...
@@ -123,7 +123,7 @@ public class AspectWeb {
if
(
isInit
)
{
TokenHelper
.
remove
();
}
aspectLogResult
.
responseLog
(
declaringType
,
TAG
,
url
,
clear
,
requestBody
,
result
,
ex
,
log
);
aspectLogResult
.
responseLog
(
log
,
result
,
ex
);
}
}
...
...
yzg-util-cloud/src/main/java/com/yanzuoguang/cloud/file/YzgFileConfig.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.
cloud
.CloudConfig
;
import
com.yanzuoguang.
util.vo
.CloudConfig
;
import
com.yanzuoguang.util.helper.FileHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.vo.file.YzgFileBaseVo
;
...
...
yzg-util-cloud/src/test/java/TestTimeout.java
View file @
557d5ee1
import
com.yanzuoguang.
cloud.aop
.Timeout
;
import
com.yanzuoguang.
log
.Timeout
;
import
com.yanzuoguang.util.thread.ThreadHelper
;
import
org.junit.Test
;
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/AspectLogResult.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/AspectLogResult.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.AspectLogBody
;
import
com.yanzuoguang.log.LogCountTime
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.
LogVo
;
import
com.yanzuoguang.util.vo.
CloudConfig
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
org.springframework.stereotype.Component
;
...
...
@@ -21,33 +18,28 @@ public class AspectLogResult {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
LogString
logString
;
private
final
LogCountTime
logCountTime
;
private
final
ResponseResult
<
String
>
responseDefault
=
ResponseResult
.
result
(
"操作成功"
);
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
LogCountTime
logCountTime
)
{
public
AspectLogResult
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
LogString
logString
,
LogCountTime
logCountTime
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
logString
=
logString
;
this
.
logCountTime
=
logCountTime
;
}
/**
* 保存日志
*
* @param cls 类型
* @param tag 标签名称
* @param url 地址
* @param logFlag 请求日志
* @param requestBody 请求内容
* @param result 结果
* @param resultEx 异常结果
* @param log 内容
* @param result 结果
* @param resultEx 异常结果
* @param log 内容
*/
// @Async
public
void
responseLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
boolean
logFlag
,
Object
requestBody
,
Object
result
,
Exception
resultEx
,
LogVo
log
)
{
public
void
responseLog
(
LogInfoVo
log
,
Object
result
,
Exception
resultEx
)
{
// 执行时间
long
time
=
System
.
currentTimeMillis
()
-
log
.
getStart
();
// 全路径
...
...
@@ -68,7 +60,7 @@ public class AspectLogResult {
logLocal
.
remove
(
log
);
return
;
}
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
String
body
=
logString
.
getBodyString
(
requestBody
);
if
(!
StringHelper
.
compare
(
log
.
getContent
(),
body
))
{
log
.
setContentTo
(
body
);
}
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/AspectLogStart.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/AspectLogStart.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.AspectLogBody
;
import
com.yanzuoguang.log.LogCountTime
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.helper.DateHelper
;
import
com.yanzuoguang.util.helper.StringHelper
;
import
com.yanzuoguang.util.log.Log
;
import
com.yanzuoguang.util.vo.
LogVo
;
import
com.yanzuoguang.util.vo.
CloudConfig
;
import
org.springframework.stereotype.Component
;
import
java.util.Date
;
/**
* 写入日志
*
...
...
@@ -18,16 +19,29 @@ public class AspectLogStart {
private
final
CloudConfig
cloudConfig
;
private
final
LogLocal
logLocal
;
private
final
AspectLogBody
aspectLogBody
;
private
final
LogString
logString
;
private
final
LogCountTime
logCountTime
;
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
AspectLogBody
aspectLogBody
,
LogCountTime
logCountTime
)
{
public
AspectLogStart
(
CloudConfig
cloudConfig
,
LogLocal
logLocal
,
LogString
logString
,
LogCountTime
logCountTime
)
{
this
.
cloudConfig
=
cloudConfig
;
this
.
logLocal
=
logLocal
;
this
.
aspectLogBody
=
aspectLogBody
;
this
.
logString
=
logString
;
this
.
logCountTime
=
logCountTime
;
}
/**
* 获取是否清空日志的标签
*
* @return 返回日志是否清空
*/
public
boolean
requestLogInit
()
{
boolean
clear
=
Log
.
threadCurrent
()
==
null
;
if
(
clear
)
{
Log
.
threadBegin
();
}
return
clear
;
}
/**
* 记录请求日志
*
...
...
@@ -37,34 +51,32 @@ public class AspectLogStart {
* @param logFlag 是否记录日志
*/
// @Async
public
LogVo
requestLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
Object
requestBody
,
boolean
logFlag
)
{
LogVo
log
=
new
LogVo
()
;
public
Log
Info
Vo
requestLog
(
Class
<?>
cls
,
String
tag
,
String
url
,
Object
requestBody
,
boolean
logFlag
)
{
String
body
;
try
{
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
logCountTime
.
start
(
fullUrl
);
String
body
=
aspectLogBody
.
getBodyString
(
requestBody
);
this
.
logLocal
.
startLog
(
log
,
tag
,
String
.
format
(
"%s:%s"
,
this
.
cloudConfig
.
getApplicationName
(),
url
),
body
);
boolean
isLog
=
logFlag
&&
this
.
cloudConfig
.
isLogCommon
();
if
(
isLog
)
{
Log
.
info
(
cls
,
" %s [ %s ] request: %s"
,
tag
,
url
,
body
);
}
body
=
logString
.
getBodyString
(
requestBody
);
}
catch
(
Exception
ex
)
{
ExceptionHelper
.
PrintError
(
AspectLogStart
.
class
,
ex
);
body
=
StringHelper
.
EMPTY
;
}
return
log
;
}
/**
* 获取是否清空日志的标签
*
* @return 返回日志是否清空
*/
public
boolean
requestLogInit
()
{
boolean
clear
=
Log
.
threadCurrent
()
==
null
;
if
(
clear
)
{
Log
.
threadBegin
();
LogInfoVo
log
=
new
LogInfoVo
();
log
.
setCreateDate
(
DateHelper
.
getDateTimeString
(
new
Date
()));
// 写入其他对象
log
.
setActionKey
(
tag
);
log
.
setActionSubKey
(
String
.
format
(
"%s:%s"
,
this
.
cloudConfig
.
getApplicationName
(),
url
));
log
.
setContent
(
body
);
// 生命日志对象爱嗯
log
.
setLogId
(
StringHelper
.
getNewID
());
this
.
logLocal
.
startLog
(
log
);
String
fullUrl
=
String
.
format
(
"%s:%s"
,
tag
,
url
);
logCountTime
.
start
(
fullUrl
);
boolean
isLog
=
logFlag
&&
this
.
cloudConfig
.
isLogCommon
();
if
(
isLog
)
{
Log
.
info
(
cls
,
" %s [ %s ] request: %s"
,
tag
,
url
,
body
);
}
return
clear
;
return
log
;
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogBase.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogBase.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.LogFeign
;
import
com.yanzuoguang.util.exception.ExceptionHelper
;
import
com.yanzuoguang.util.thread.ThreadNext
;
import
com.yanzuoguang.util.vo.
LogVo
;
import
com.yanzuoguang.util.vo.
CloudConfig
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
...
...
@@ -21,7 +19,7 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
/**
* 缓存队列
*/
protected
volatile
LinkedBlockingQueue
<
LogVo
>
cache
=
new
LinkedBlockingQueue
<>();
protected
volatile
LinkedBlockingQueue
<
Log
Info
Vo
>
cache
=
new
LinkedBlockingQueue
<>();
private
final
CloudConfig
cloudConfig
;
private
final
LogFeignBase
logFeign
;
...
...
@@ -57,9 +55,9 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
/**
* 添加日志到缓存中,并不是立即添加,而是通过线程执行,防止对环境造成影响
*
* @param logVo
* @param logVo
日志信息
*/
public
void
addLog
(
LogVo
logVo
)
{
public
void
addLog
(
Log
Info
Vo
logVo
)
{
// 当不记录日志时,则直接忽略
if
(!
cloudConfig
.
isLogBase
())
{
return
;
...
...
@@ -71,7 +69,6 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
* 执行下一个函数,出现异常会继续执行
*
* @return 是否继续执行
* @throws Exception 异常信息
*/
@Override
public
boolean
next
()
{
...
...
@@ -79,7 +76,7 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
return
true
;
}
// 循环处理日志信息
while
(
cache
.
size
()
>
0
)
{
while
(
!
cache
.
isEmpty
()
)
{
// 取出一条日志
LogVo
item
=
cache
.
poll
();
// 判断日志信息是否为空
...
...
@@ -99,7 +96,7 @@ public class LogBase implements ThreadNext.Next, InitializingBean {
/**
* 沉睡时间
*
* @return
* @return
下次执行时间
*/
@Override
public
int
getNextTime
()
{
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/LogFeign.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log
/LogFeign.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
import
com.yanzuoguang.cloud.aop.log.LogFeignBase
;
package
com
.
yanzuoguang
.
log
;
/**
* 调用外置服务保存日志对象
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogFeignBase.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogFeignBase.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.vo.LogVo
;
import
com.yanzuoguang.util.vo.ResponseResult
;
/**
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogFeignDefault.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogFeignDefault.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.vo.LogVo
;
import
com.yanzuoguang.util.vo.ResponseResult
;
import
org.springframework.stereotype.Component
;
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogFilter.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogFilter.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
java.util.List
;
...
...
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogFilterDefault.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogFilterDefault.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.util.helper.StringHelper
;
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogInfoVo.java
0 → 100644
View file @
557d5ee1
package
com
.
yanzuoguang
.
log
;
import
io.swagger.annotations.ApiModelProperty
;
public
class
LogInfoVo
extends
LogVo
{
/**
* 开始时间
*/
@ApiModelProperty
(
value
=
"开始时间"
,
notes
=
"单位(毫秒)"
)
private
long
start
=
System
.
currentTimeMillis
();
public
long
getStart
()
{
return
start
;
}
public
void
setStart
(
long
start
)
{
this
.
start
=
start
;
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/log/LogLocal.java
→
yzg-util-
db/src/main/java/com/yanzuoguang
/log/LogLocal.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
.
log
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.cloud.CloudConfig
;
import
com.yanzuoguang.cloud.aop.Timeout
;
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
com.yanzuoguang.util.vo.
LogVo
;
import
com.yanzuoguang.util.vo.
CloudConfig
;
import
org.springframework.beans.factory.InitializingBean
;
import
org.springframework.stereotype.Component
;
import
java.util.*
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collection
;
import
java.util.List
;
/**
* 当前线程日志编写
...
...
@@ -19,7 +19,6 @@ import java.util.*;
*/
@Component
public
class
LogLocal
implements
ThreadNext
.
Next
,
InitializingBean
{
/**
* 一个请求最多保留60分钟
*/
...
...
@@ -38,7 +37,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
/**
* 缓存队列
*/
protected
volatile
MemoryCache
<
Timeout
<
LogVo
>>
cache
=
new
MemoryCache
<>(
CLEAR_CACHE
);
protected
volatile
MemoryCache
<
Timeout
<
Log
Info
Vo
>>
cache
=
new
MemoryCache
<>(
CLEAR_CACHE
);
public
LogLocal
(
LogBase
logBase
,
CloudConfig
cloudConfig
,
List
<
LogFilter
>
logFilters
)
{
this
.
logBase
=
logBase
;
...
...
@@ -55,21 +54,10 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* 开始记录日志
*
* @param log 日志对象
* @param actionKey 功能名称
* @param actionSubKey 子功能名称 = 服务名称 + 地址
* @param content 请求内容
*/
public
void
startLog
(
Log
Vo
log
,
String
actionKey
,
String
actionSubKey
,
String
content
)
{
public
void
startLog
(
Log
InfoVo
log
)
{
// 声明超时对象
Timeout
<
LogVo
>
time
=
new
Timeout
<>(
log
);
log
.
setCreateDate
(
DateHelper
.
getDateTimeString
(
new
Date
(
time
.
getStart
())));
// 写入其他对象
log
.
setActionKey
(
actionKey
);
log
.
setActionSubKey
(
actionSubKey
);
log
.
setContent
(
content
);
// 生命日志对象爱嗯
log
.
setLogId
(
StringHelper
.
getNewID
());
Timeout
<
LogInfoVo
>
time
=
new
Timeout
<>(
log
);
cache
.
put
(
log
.
getLogId
(),
time
);
}
...
...
@@ -81,7 +69,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @param result 结果
* @param isError 是否出错
*/
public
void
result
(
LogVo
log
,
String
status
,
String
result
,
boolean
isError
)
{
public
void
result
(
Log
Info
Vo
log
,
String
status
,
String
result
,
boolean
isError
)
{
if
(
log
==
null
)
{
return
;
}
...
...
@@ -102,11 +90,11 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
* @param result 结果
* @param write 写入
*/
private
void
resultWrite
(
LogVo
log
,
String
status
,
String
result
,
boolean
write
)
{
private
void
resultWrite
(
Log
Info
Vo
log
,
String
status
,
String
result
,
boolean
write
)
{
if
(
log
==
null
||
StringHelper
.
isEmpty
(
log
.
getLogId
()))
{
return
;
}
Timeout
<
LogVo
>
timeout
;
Timeout
<
Log
Info
Vo
>
timeout
;
// 判断是否延时结果
boolean
isMaxTime
=
StringHelper
.
compare
(
status
,
MAX_TIME
);
if
(
isMaxTime
)
{
...
...
@@ -131,7 +119,7 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*
* @param log 删除日志
*/
public
void
remove
(
LogVo
log
)
{
public
void
remove
(
Log
Info
Vo
log
)
{
this
.
resultWrite
(
log
,
StringHelper
.
EMPTY
,
StringHelper
.
EMPTY
,
false
);
}
...
...
@@ -165,8 +153,8 @@ public class LogLocal implements ThreadNext.Next, InitializingBean {
*/
@Override
public
boolean
next
()
{
Collection
<
Timeout
<
LogVo
>>
values
=
cache
.
getValues
();
for
(
Timeout
<
LogVo
>
timeout
:
values
)
{
Collection
<
Timeout
<
Log
Info
Vo
>>
values
=
cache
.
getValues
();
for
(
Timeout
<
Log
Info
Vo
>
timeout
:
values
)
{
if
(
timeout
==
null
)
{
continue
;
}
...
...
yzg-util-db/src/main/java/com/yanzuoguang/log/LogString.java
0 → 100644
View file @
557d5ee1
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
com.yanzuoguang.util.vo.CloudConfig
;
import
org.springframework.stereotype.Component
;
/**
* 获取日志字符串
*
* @author 颜佐光
*/
@Component
public
class
LogString
{
private
final
CloudConfig
cloudConfig
;
public
LogString
(
CloudConfig
cloudConfig
)
{
this
.
cloudConfig
=
cloudConfig
;
}
/**
* 获取JSON,当Json过长时,截断
*
* @param paraJson 长json字符串
* @return 短json字符串
*/
public
String
getMaxString
(
String
paraJson
)
{
if
(
paraJson
!=
null
&&
paraJson
.
length
()
>
this
.
cloudConfig
.
getReqSize
())
{
paraJson
=
paraJson
.
substring
(
0
,
this
.
cloudConfig
.
getReqSize
());
}
return
paraJson
;
}
/**
* 获取内容转换为字符串
*
* @param body 内容
* @return 字符串
*/
public
String
getBodyString
(
Object
body
)
{
String
ret
;
if
(
body
instanceof
String
)
{
ret
=
getMaxString
((
String
)
body
);
}
else
{
ret
=
getMaxString
(
JsonHelper
.
serialize
(
body
));
}
return
ret
;
}
}
yzg-util-
base/src/main/java/com/yanzuoguang/util/vo
/LogVo.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log
/LogVo.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
util
.
vo
;
package
com
.
yanzuoguang
.
log
;
import
com.yanzuoguang.util.vo.BaseVo
;
import
io.swagger.annotations.ApiModel
;
import
io.swagger.annotations.ApiModelProperty
;
...
...
@@ -45,7 +46,7 @@ public class LogVo extends BaseVo {
/**
* 接口处理状态,是否有异常
*/
@ApiModelProperty
(
value
=
"执行状态"
,
notes
=
"0表示成功,其他状态表示失败"
,
required
=
true
,
example
=
"0"
)
@ApiModelProperty
(
value
=
"执行状态"
,
notes
=
"0表示成功,其他状态表示失败
,-1表示执行中
"
,
required
=
true
,
example
=
"0"
)
private
String
status
;
/**
* 使用时间
...
...
@@ -57,11 +58,6 @@ public class LogVo extends BaseVo {
*/
@ApiModelProperty
(
value
=
"创建时间"
,
notes
=
"单位(毫秒)"
,
required
=
false
,
example
=
"1987-11-24 23:15:18"
)
private
String
createDate
;
/**
* 开始时间
*/
@ApiModelProperty
(
value
=
"开始时间"
,
notes
=
"单位(毫秒)"
)
private
long
start
=
System
.
currentTimeMillis
();
public
String
getLogId
()
{
return
logId
;
...
...
@@ -134,12 +130,4 @@ public class LogVo extends BaseVo {
public
void
setCreateDate
(
String
createDate
)
{
this
.
createDate
=
createDate
;
}
public
long
getStart
()
{
return
start
;
}
public
void
setStart
(
long
start
)
{
this
.
start
=
start
;
}
}
yzg-util-
cloud/src/main/java/com/yanzuoguang/cloud/aop
/Timeout.java
→
yzg-util-
db/src/main/java/com/yanzuoguang/log
/Timeout.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
aop
;
package
com
.
yanzuoguang
.
log
;
/**
* 超时对象
...
...
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgExcelService.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.
cloud
.CloudConfig
;
import
com.yanzuoguang.
util.vo
.CloudConfig
;
import
com.yanzuoguang.cloud.file.dao.YzgFileDao
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.cloud.vo.YzgFileVo
;
...
...
yzg-util-file/src/main/java/com/yanzuoguang/cloud/file/YzgFileServiceImpl.java
View file @
557d5ee1
package
com
.
yanzuoguang
.
cloud
.
file
;
import
com.yanzuoguang.
cloud
.CloudConfig
;
import
com.yanzuoguang.
util.vo
.CloudConfig
;
import
com.yanzuoguang.cloud.helper.HttpFileHelper
;
import
com.yanzuoguang.cloud.vo.YzgFileUploadReqVo
;
import
com.yanzuoguang.util.MediaHelper
;
...
...
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