调整HTTP日志输出
This commit is contained in:
parent
e0669e98cf
commit
3510a565f2
@ -36,7 +36,6 @@ public abstract class HttpCallback extends AbsCallback<JsonBean> {
|
|||||||
public void onSuccess(Response<JsonBean> response) {
|
public void onSuccess(Response<JsonBean> response) {
|
||||||
JsonBean bean = response.body();
|
JsonBean bean = response.body();
|
||||||
String gson = new Gson().toJson(bean);
|
String gson = new Gson().toJson(bean);
|
||||||
Log.e("onSuccess", gson);
|
|
||||||
if (bean != null) {
|
if (bean != null) {
|
||||||
if (200 == bean.getRet()) {
|
if (200 == bean.getRet()) {
|
||||||
Data data = bean.getData();
|
Data data = bean.getData();
|
||||||
|
@ -133,15 +133,18 @@ public class HttpLoggingInterceptor implements Interceptor {
|
|||||||
ResponseBody responseBody = clone.body();
|
ResponseBody responseBody = clone.body();
|
||||||
boolean logBody = (printLevel == Level.BODY);
|
boolean logBody = (printLevel == Level.BODY);
|
||||||
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
||||||
|
StringBuilder sb=new StringBuilder();
|
||||||
try {
|
try {
|
||||||
log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
|
sb.append("<-- ").append(clone.code())
|
||||||
|
.append(' ').append(clone.message())
|
||||||
|
.append(' ').append(clone.request().url())
|
||||||
|
.append(" (").append(tookMs).append("ms)\n");
|
||||||
if (logHeaders) {
|
if (logHeaders) {
|
||||||
Headers headers = clone.headers();
|
Headers headers = clone.headers();
|
||||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||||
log("\t" + headers.name(i) + ": " + headers.value(i));
|
sb.append("\t").append(headers.name(i)).append(": ").append(headers.value(i)).append("\n");
|
||||||
}
|
}
|
||||||
log(" ");
|
sb.append("\n");
|
||||||
if (logBody && HttpHeaders.hasBody(clone)) {
|
if (logBody && HttpHeaders.hasBody(clone)) {
|
||||||
if (responseBody == null) return response;
|
if (responseBody == null) return response;
|
||||||
|
|
||||||
@ -149,18 +152,19 @@ public class HttpLoggingInterceptor implements Interceptor {
|
|||||||
byte[] bytes = IOUtils.toByteArray(responseBody.byteStream());
|
byte[] bytes = IOUtils.toByteArray(responseBody.byteStream());
|
||||||
MediaType contentType = responseBody.contentType();
|
MediaType contentType = responseBody.contentType();
|
||||||
String body = new String(bytes, getCharset(contentType));
|
String body = new String(bytes, getCharset(contentType));
|
||||||
log("\tbody:" + body);
|
sb.append("\tbody:").append(body).append("\n");
|
||||||
responseBody = ResponseBody.create(responseBody.contentType(), bytes);
|
responseBody = ResponseBody.create(responseBody.contentType(), bytes);
|
||||||
return response.newBuilder().body(responseBody).build();
|
return response.newBuilder().body(responseBody).build();
|
||||||
} else {
|
} else {
|
||||||
log("\tbody: maybe [binary body], omitted!");
|
sb.append("\tbody: maybe [binary body], omitted!").append("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
OkLogger.printStackTrace(e);
|
OkLogger.printStackTrace(e);
|
||||||
} finally {
|
} finally {
|
||||||
log("<-- END HTTP");
|
sb.append("<-- END HTTP").append("\n");
|
||||||
|
log(sb.toString());
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,9 @@ public class UploadQnImpl implements UploadStrategy {
|
|||||||
assert response != null;
|
assert response != null;
|
||||||
mList.get(mIndex).setRemoteAccessUrl(response.getString("key"));
|
mList.get(mIndex).setRemoteAccessUrl(response.getString("key"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
throw new RuntimeException(e);
|
// throw new RuntimeException(e);
|
||||||
|
L.e(e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (mList == null || mList.size() == 0) {
|
if (mList == null || mList.size() == 0) {
|
||||||
if (mUploadCallback != null) {
|
if (mUploadCallback != null) {
|
||||||
|
@ -2,6 +2,8 @@ package com.yunbao.common.utils;
|
|||||||
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
@ -42,6 +44,10 @@ public class L {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void setDeBug(boolean deBug) {
|
public static void setDeBug(boolean deBug) {
|
||||||
sDeBug = false;
|
sDeBug = deBug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void e(Exception e) {
|
||||||
|
Log.e("Exception", e.getMessage(), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -160,7 +160,6 @@ public class LogUtil {
|
|||||||
ZipUtils.zipFolder(srcList, zip.getAbsolutePath(), filters, new Runnable() {
|
ZipUtils.zipFolder(srcList, zip.getAbsolutePath(), filters, new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
System.out.println("!!!!!!!!!!!!!!!!!!!");
|
|
||||||
if (BuildConfig.DEBUG) {
|
if (BuildConfig.DEBUG) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,6 @@ public class LogUtils {
|
|||||||
|
|
||||||
public static void endSafeLog() {
|
public static void endSafeLog() {
|
||||||
writerSafeLog = false;
|
writerSafeLog = false;
|
||||||
while (!QUEUE.isEmpty()){
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user