Skip to content

Commit

Permalink
项目重构
Browse files Browse the repository at this point in the history
  • Loading branch information
RockyQu committed May 5, 2018
1 parent 069a877 commit d44a457
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public Response intercept(Chain chain) throws IOException {
*/
private Request resolveRequestLogger(StringBuilder builder, Chain chain) throws IOException {
Request request = chain.request();
if (level == Level.NONE) {
return request;
}

boolean hasSimpleLog = level == Level.SIMPLE;

RequestBody requestBody = request.body();
boolean hasRequestBody = requestBody != null;
Expand All @@ -124,7 +129,7 @@ private Request resolveRequestLogger(StringBuilder builder, Chain chain) throws

builder.append(LoggConstant.BR);

if (hasRequestBody) {
if (hasRequestBody && hasSimpleLog) {
if (requestBody.contentType() != null) {
builder.append("Content-Type: ").append(requestBody.contentType()).append(LoggConstant.BR);
}
Expand Down Expand Up @@ -190,16 +195,15 @@ private Request resolveRequestLogger(StringBuilder builder, Chain chain) throws
private Response resolveResponseLogger(StringBuilder builder, Chain chain) throws IOException {
long startNs = System.nanoTime();

Response response;
try {
response = chain.proceed(chain.request());
} catch (Exception e) {
builder.append("<-- HTTP FAILED: ").append(e);
throw e;
Response response = chain.proceed(chain.request());
if (level == Level.NONE) {
return response;
}

long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);

boolean hasSimpleLog = level == Level.SIMPLE;

ResponseBody responseBody = response.body();
boolean hasResponseBody = responseBody != null;

Expand Down

0 comments on commit d44a457

Please sign in to comment.