log打印添加重定向
This commit is contained in:
@@ -48,7 +48,8 @@ public class DataLoggingInterceptor implements Interceptor {
|
|||||||
private final Logger logger;
|
private final Logger logger;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override public Response intercept(@NonNull Chain chain) throws IOException {
|
@Override
|
||||||
|
public Response intercept(@NonNull Chain chain) throws IOException {
|
||||||
Request request = chain.request();
|
Request request = chain.request();
|
||||||
|
|
||||||
logger.reset();
|
logger.reset();
|
||||||
@@ -135,8 +136,11 @@ public class DataLoggingInterceptor implements Interceptor {
|
|||||||
if (responseBody != null) {
|
if (responseBody != null) {
|
||||||
long contentLength = responseBody.contentLength();
|
long contentLength = responseBody.contentLength();
|
||||||
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
|
String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
|
||||||
|
// logger.log(response.code() + " " + response.message() + " "
|
||||||
|
// + response.request().url() + " (" + tookMs + "ms)");
|
||||||
|
|
||||||
logger.log(response.code() + " " + response.message() + " "
|
logger.log(response.code() + " " + response.message() + " "
|
||||||
+ response.request().url() + " (" + tookMs + "ms)");
|
+ response.request().url() + " → " + response.networkResponse().request().url() + " (" + tookMs + "ms)");
|
||||||
|
|
||||||
Headers headers = response.headers();
|
Headers headers = response.headers();
|
||||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import android.util.Log;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.blankj.utilcode.util.LogUtils;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -34,7 +36,7 @@ public class LogInterceptor implements Interceptor {
|
|||||||
|
|
||||||
private boolean logResponseBody = true;
|
private boolean logResponseBody = true;
|
||||||
// 最大日志长度(避免过大的响应体导致日志刷屏)
|
// 最大日志长度(避免过大的响应体导致日志刷屏)
|
||||||
private int maxLogLength = 2048;
|
private int maxLogLength = 2048 * 2;
|
||||||
|
|
||||||
public LogInterceptor() {
|
public LogInterceptor() {
|
||||||
}
|
}
|
||||||
@@ -136,9 +138,18 @@ public class LogInterceptor implements Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.append("==================== 请求结束 ====================\n");
|
log.append("==================== 请求结束 ====================\n");
|
||||||
Log.d(TAG, log.toString());
|
// LogUtils.d(TAG, log.toString());
|
||||||
|
if (log.toString().contains("Xintiao/keep_xintiao"))
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
LogUtils.d(log.toString());
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
// 处理异常,记录日志或使用默认值
|
||||||
|
LogUtils.e("打印 JSON 数据时出错:" + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "打印请求日志失败: " + e.getMessage());
|
LogUtils.e(TAG, "打印请求日志失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -186,9 +197,18 @@ public class LogInterceptor implements Interceptor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
log.append("==================== 响应结束 ====================\n");
|
log.append("==================== 响应结束 ====================\n");
|
||||||
Log.d(TAG, log.toString());
|
// LogUtils.d(TAG, log.toString());
|
||||||
|
|
||||||
|
if (log.toString().contains("Xintiao/keep_xintiao"))
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
LogUtils.d(log.toString());
|
||||||
|
} catch (StringIndexOutOfBoundsException e) {
|
||||||
|
// 处理异常,记录日志或使用默认值
|
||||||
|
LogUtils.e("打印 JSON 数据时出错:" + e.getMessage());
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "打印响应日志失败: " + e.getMessage());
|
LogUtils.e(TAG, "打印响应日志失败: " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user