Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
YDL-Component-Medical
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨凯
YDL-Component-Medical
Commits
f9b0977b
Commit
f9b0977b
authored
Jul 29, 2022
by
YKai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 注释掉http请求的日志打印
parent
0d167ce7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
39 deletions
+39
-39
RequestLogInterceptor.java
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
+39
-39
No files found.
ydl-net/src/main/java/com/ydl/ydlnet/builder/interceptor/log/RequestLogInterceptor.java
View file @
f9b0977b
...
...
@@ -28,7 +28,7 @@ import okio.BufferedSource;
* Des: 解析框架中的网络请求和响应结果并打印
*/
public
class
RequestLogInterceptor
implements
Interceptor
{
private
DefaultFormatPrinter
mPrinter
=
new
DefaultFormatPrinter
();
//
private DefaultFormatPrinter mPrinter = new DefaultFormatPrinter();
private
boolean
mIsDebug
;
private
RequestHandler
mRequestHandler
;
...
...
@@ -40,18 +40,18 @@ public class RequestLogInterceptor implements Interceptor {
@Override
public
Response
intercept
(
Chain
chain
)
throws
IOException
{
Request
request
=
chain
.
request
();
//打印请求信息
if
(
request
.
body
()
!=
null
&&
isParseable
(
request
.
body
().
contentType
()))
{
mPrinter
.
printJsonRequest
(
request
,
parseParams
(
request
));
}
else
{
mPrinter
.
printFileRequest
(
request
);
}
if
(
mRequestHandler
!=
null
)
{
request
=
mRequestHandler
.
onHttpRequestBefore
(
chain
,
request
);
}
long
t1
=
System
.
nanoTime
();
//
//
//打印请求信息
//
if (request.body() != null && isParseable(request.body().contentType())) {
//
mPrinter.printJsonRequest(request, parseParams(request));
//
} else {
//
mPrinter.printFileRequest(request);
//
}
//
//
if (mRequestHandler != null) {
//
request = mRequestHandler.onHttpRequestBefore(chain, request);
//
}
//
long t1 = System.nanoTime();
Response
originalResponse
;
try
{
originalResponse
=
chain
.
proceed
(
request
);
...
...
@@ -59,35 +59,35 @@ public class RequestLogInterceptor implements Interceptor {
NetLogUtils
.
debugInfo
(
"Http Error: "
+
e
);
throw
e
;
}
long
t2
=
System
.
nanoTime
();
//
long t2 = System.nanoTime();
ResponseBody
responseBody
=
originalResponse
.
body
();
//
ResponseBody responseBody = originalResponse.body();
//打印响应结果
String
bodyString
=
null
;
if
(
responseBody
!=
null
&&
isParseable
(
responseBody
.
contentType
()))
{
bodyString
=
printResult
(
request
,
originalResponse
);
if
(
mRequestHandler
!=
null
)
{
mRequestHandler
.
onHttpResultResponse
(
bodyString
,
chain
,
originalResponse
);
}
}
if
(
mIsDebug
)
{
final
List
<
String
>
segmentList
=
request
.
url
().
encodedPathSegments
();
final
String
header
=
originalResponse
.
headers
().
toString
();
final
int
code
=
originalResponse
.
code
();
final
boolean
isSuccessful
=
originalResponse
.
isSuccessful
();
final
String
message
=
originalResponse
.
message
();
final
String
url
=
originalResponse
.
request
().
url
().
toString
();
if
(
responseBody
!=
null
&&
isParseable
(
responseBody
.
contentType
()))
{
mPrinter
.
printJsonResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
responseBody
.
contentType
(),
bodyString
,
segmentList
,
message
,
url
);
}
else
{
mPrinter
.
printFileResponse
(
TimeUnit
.
NANOSECONDS
.
toMillis
(
t2
-
t1
),
isSuccessful
,
code
,
header
,
segmentList
,
message
,
url
);
}
}
//
String bodyString = null;
//
if (responseBody != null && isParseable(responseBody.contentType())) {
//
bodyString = printResult(request, originalResponse);
//
if (mRequestHandler != null) {
//
mRequestHandler.onHttpResultResponse(bodyString, chain, originalResponse);
//
}
//
}
//
//
if (mIsDebug) {
//
final List<String> segmentList = request.url().encodedPathSegments();
//
final String header = originalResponse.headers().toString();
//
final int code = originalResponse.code();
//
final boolean isSuccessful = originalResponse.isSuccessful();
//
final String message = originalResponse.message();
//
final String url = originalResponse.request().url().toString();
//
//
if (responseBody != null && isParseable(responseBody.contentType())) {
//
mPrinter.printJsonResponse(TimeUnit.NANOSECONDS.toMillis(t2 - t1), isSuccessful,
//
code, header, responseBody.contentType(), bodyString, segmentList, message, url);
//
} else {
//
mPrinter.printFileResponse(TimeUnit.NANOSECONDS.toMillis(t2 - t1),
//
isSuccessful, code, header, segmentList, message, url);
//
}
//
}
return
originalResponse
;
}
...
...
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