106 lines
3.6 KiB
Java
106 lines
3.6 KiB
Java
package okhttp3.internal.platform.android;
|
|
|
|
import android.util.Log;
|
|
import java.util.LinkedHashMap;
|
|
import java.util.Map;
|
|
import java.util.concurrent.CopyOnWriteArraySet;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import o.C14856gaP;
|
|
import o.C14957gcv;
|
|
import o.gdZ;
|
|
import okhttp3.OkHttpClient;
|
|
import okhttp3.internal.concurrent.TaskRunner;
|
|
import okhttp3.internal.http2.Http2;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class AndroidLog {
|
|
private static final int MAX_LOG_LENGTH = 4000;
|
|
private static final Map<String, String> knownLoggers;
|
|
public static final AndroidLog INSTANCE = new AndroidLog();
|
|
private static final CopyOnWriteArraySet<Logger> configuredLoggers = new CopyOnWriteArraySet<>();
|
|
|
|
private AndroidLog() {
|
|
}
|
|
|
|
static {
|
|
LinkedHashMap linkedHashMap = new LinkedHashMap();
|
|
Package r1 = OkHttpClient.class.getPackage();
|
|
String name = r1 == null ? null : r1.getName();
|
|
if (name != null) {
|
|
linkedHashMap.put(name, "OkHttp");
|
|
}
|
|
LinkedHashMap linkedHashMap2 = linkedHashMap;
|
|
String name2 = OkHttpClient.class.getName();
|
|
C14957gcv.c((Object) name2, "");
|
|
linkedHashMap2.put(name2, "okhttp.OkHttpClient");
|
|
String name3 = Http2.class.getName();
|
|
C14957gcv.c((Object) name3, "");
|
|
linkedHashMap2.put(name3, "okhttp.Http2");
|
|
String name4 = TaskRunner.class.getName();
|
|
C14957gcv.c((Object) name4, "");
|
|
linkedHashMap2.put(name4, "okhttp.TaskRunner");
|
|
linkedHashMap2.put("okhttp3.mockwebserver.MockWebServer", "okhttp.MockWebServer");
|
|
knownLoggers = C14856gaP.c(linkedHashMap2);
|
|
}
|
|
|
|
public final void androidLog$okhttp(String str, int i, String str2, Throwable th) {
|
|
int min;
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(str2, "");
|
|
if (Log.isLoggable(loggerTag(str), i)) {
|
|
if (th != null) {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(str2);
|
|
sb.append('\n');
|
|
sb.append((Object) Log.getStackTraceString(th));
|
|
str2 = sb.toString();
|
|
}
|
|
int length = str2.length();
|
|
int i2 = 0;
|
|
while (i2 < length) {
|
|
int a = gdZ.a((CharSequence) str2, '\n', i2, false);
|
|
if (a == -1) {
|
|
a = length;
|
|
}
|
|
while (true) {
|
|
min = Math.min(a, i2 + MAX_LOG_LENGTH);
|
|
C14957gcv.c((Object) str2.substring(i2, min), "");
|
|
if (min >= a) {
|
|
break;
|
|
} else {
|
|
i2 = min;
|
|
}
|
|
}
|
|
i2 = min + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private final String loggerTag(String str) {
|
|
String str2 = knownLoggers.get(str);
|
|
return str2 == null ? gdZ.b(str, 23) : str2;
|
|
}
|
|
|
|
public final void enable() {
|
|
for (Map.Entry<String, String> entry : knownLoggers.entrySet()) {
|
|
enableLogging(entry.getKey(), entry.getValue());
|
|
}
|
|
}
|
|
|
|
private final void enableLogging(String str, String str2) {
|
|
Level level;
|
|
Logger logger = Logger.getLogger(str);
|
|
if (configuredLoggers.add(logger)) {
|
|
logger.setUseParentHandlers(false);
|
|
if (Log.isLoggable(str2, 3)) {
|
|
level = Level.FINE;
|
|
} else {
|
|
level = Log.isLoggable(str2, 4) ? Level.INFO : Level.WARNING;
|
|
}
|
|
logger.setLevel(level);
|
|
logger.addHandler(AndroidLogHandler.INSTANCE);
|
|
}
|
|
}
|
|
}
|