Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
order-group
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
jenkins
order-group
Commits
c374c7bf
Commit
c374c7bf
authored
Mar 24, 2020
by
dingkai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
异常日志测试
parent
ac91ec33
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
shopping-cart-application-service/src/main/java/cn/freemud/controller/TestExceptionController.java
+61
-0
No files found.
shopping-cart-application-service/src/main/java/cn/freemud/controller/TestExceptionController.java
0 → 100644
View file @
c374c7bf
package
cn
.
freemud
.
controller
;
import
ch.qos.logback.classic.Level
;
import
com.alibaba.fastjson.JSONObject
;
import
com.freemud.application.sdk.api.base.SDKCommonBaseContextWare
;
import
com.freemud.application.sdk.api.log.ErrorLog
;
import
com.freemud.application.sdk.api.log.LogThreadLocal
;
import
org.apache.commons.lang.StringUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.io.ByteArrayOutputStream
;
import
java.io.PrintStream
;
@RestController
public
class
TestExceptionController
{
private
static
Logger
logger
=
LoggerFactory
.
getLogger
(
TestExceptionController
.
class
);
@RequestMapping
(
value
=
"test/exception"
)
public
void
test
()
{
try
{
throw
new
NullPointerException
();
}
catch
(
Exception
e
)
{
ErrorLog
.
infoConvertJson
(
this
.
getClass
(),
"testException1"
,
e
);
infoConvertJson
(
this
.
getClass
(),
"testExceptionV2"
,
e
);
infoConvertJson2
(
this
.
getClass
(),
"testExceptionV3"
,
e
);
infoConvertJson3
(
this
.
getClass
(),
"testExceptionV4"
,
e
);
}
}
public
static
void
infoConvertJson
(
Class
logClass
,
String
message
,
Exception
ex
)
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ex
.
printStackTrace
(
new
PrintStream
(
baos
));
String
exception
=
baos
.
toString
();
printLog
(
SDKCommonBaseContextWare
.
getAppName
(),
LogThreadLocal
.
getTrackingNo
(),
logClass
,
message
,
exception
,
Level
.
ERROR
);
}
public
static
void
printLog
(
String
appName
,
String
trackingNo
,
Class
logClass
,
String
message
,
Object
object
,
Level
level
)
{
logger
.
error
(
"appName:{} trackingNo:{} className{} level:{} messasge:{} stackTrack:{}"
,
appName
,
trackingNo
,
logClass
,
level
.
levelStr
,
message
,
object
);
}
public
static
void
infoConvertJson2
(
Class
logClass
,
String
message
,
Exception
ex
)
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ex
.
printStackTrace
(
new
PrintStream
(
baos
));
String
exception
=
baos
.
toString
();
exception
=
StringUtils
.
replace
(
exception
,
"\\t"
,
""
);
printLog
(
SDKCommonBaseContextWare
.
getAppName
(),
LogThreadLocal
.
getTrackingNo
(),
logClass
,
message
,
exception
,
Level
.
ERROR
);
}
public
static
void
infoConvertJson3
(
Class
logClass
,
String
message
,
Exception
ex
)
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
ex
.
printStackTrace
(
new
PrintStream
(
baos
));
String
exception
=
baos
.
toString
();
exception
=
StringUtils
.
replace
(
exception
,
"\\n\\t"
,
","
);
printLog
(
SDKCommonBaseContextWare
.
getAppName
(),
LogThreadLocal
.
getTrackingNo
(),
logClass
,
message
,
exception
,
Level
.
ERROR
);
}
}
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