Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
D
dinglog-spring-boot-started
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
VCC
dinglog-spring-boot-started
Commits
7c81710e
Commit
7c81710e
authored
Mar 08, 2021
by
王雪飞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
13d48467
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
3 deletions
+45
-3
LogErrorSendMsgUtil.java
.../java/cn/quantgroup/dinglog/util/LogErrorSendMsgUtil.java
+45
-3
No files found.
src/main/java/cn/quantgroup/dinglog/util/LogErrorSendMsgUtil.java
View file @
7c81710e
package
cn
.
quantgroup
.
dinglog
.
util
;
import
ch.qos.logback.classic.spi.IThrowableProxy
;
import
ch.qos.logback.classic.spi.StackTraceElementProxy
;
import
cn.quantgroup.dinglog.config.DingTalkHookLogErrorConfig
;
import
com.alibaba.fastjson.JSON
;
import
com.taobao.api.Constants
;
import
com.taobao.api.internal.util.HttpResponseData
;
import
com.taobao.api.internal.util.WebV2Utils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.beans.factory.annotation.Value
;
...
...
@@ -37,6 +40,45 @@ public class LogErrorSendMsgUtil {
return
new
Thread
(
r
,
"钉钉log错误消息"
);
}},
new
ThreadPoolExecutor
.
DiscardOldestPolicy
());
public
static
void
sendMsg
(
String
msg
,
Throwable
e
){
if
(
msg
==
null
)
{
return
;
}
if
(!
DingTalkHookLogErrorConfig
.
isEnable
()){
return
;
}
if
(
e
!=
null
){
msg
=
msg
+
"\n"
+
getStackTraceElementMessage
(
e
);
}
sendMsg
(
msg
);
}
public
static
String
getStackTraceElementMessage
(
Throwable
ex
){
int
index
=
0
;
String
errorMessage
=
""
;
StackTraceElement
[]
stackTraceElements
=
ex
.
getStackTrace
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
ex
.
fillInStackTrace
()+
" "
);
for
(
StackTraceElement
stackTraceElement:
stackTraceElements
){
if
(
index
>
3
){
return
errorMessage
;
}
String
className
=
stackTraceElement
.
getClassName
();
if
(
className
.
contains
(
"quantgroup"
)
||
className
.
contains
(
".qg."
)||
className
.
contains
(
".xyqb."
)||
className
.
contains
(
".lkb."
)||
className
.
contains
(
".liangkebang."
)
){
index
++;
sb
.
append
(
stackTraceElement
.
getClassName
()
+
"."
+
stackTraceElement
.
getMethodName
()
+
"("
+
stackTraceElement
.
getFileName
()
+
":"
+
stackTraceElement
.
getLineNumber
()
+
") "
);
errorMessage
=
sb
.
toString
();
}
}
return
errorMessage
;
}
public
static
void
sendMsg
(
String
msg
){
if
(!
DingTalkHookLogErrorConfig
.
isEnable
()){
return
;
...
...
@@ -66,10 +108,10 @@ public class LogErrorSendMsgUtil {
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
if
(
responseData
.
getBody
()!=
null
){
logger
.
info
(
"项目名{},环境={},发送
失败
"
,
project_name
,
System
.
getProperty
(
"env"
));
if
(
responseData
.
getBody
()!=
null
&&
responseData
.
getBody
().
contains
(
"ok"
)
){
logger
.
info
(
"项目名{},环境={},发送
成功
"
,
project_name
,
System
.
getProperty
(
"env"
));
}
else
{
logger
.
info
(
"项目名{},环境={}, 发送
成功
"
,
project_name
,
System
.
getProperty
(
"env"
));
logger
.
info
(
"项目名{},环境={}, 发送
失败
"
,
project_name
,
System
.
getProperty
(
"env"
));
}
});
...
...
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