- Added realracing3-community.apk (71.57 MB) - Removed 32-bit support (armeabi-v7a) - Only includes arm64-v8a libraries - Decompiled source code included - Added README-community.md with analysis
97 lines
3.8 KiB
Java
97 lines
3.8 KiB
Java
package com.helpshift.log;
|
|
|
|
import android.content.Context;
|
|
import android.util.Log;
|
|
import com.helpshift.log.ILogger;
|
|
import com.helpshift.util.Utils;
|
|
import java.io.File;
|
|
import java.io.FileOutputStream;
|
|
import java.net.UnknownHostException;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Arrays;
|
|
import java.util.Date;
|
|
import java.util.Locale;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
|
|
/* loaded from: classes3.dex */
|
|
public class LogCollector {
|
|
public static final String logDirPath = "helpshift" + File.separator + "debugLogs";
|
|
public FileOutputStream fos;
|
|
public final File logFile;
|
|
public final long mainThreadId;
|
|
public final ExecutorService executorService = Executors.newSingleThreadExecutor();
|
|
public final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.US);
|
|
|
|
public LogCollector(Context context, String str, long j) {
|
|
File file = new File(context.getFilesDir(), logDirPath);
|
|
file.mkdirs();
|
|
deleteOldFiles(file);
|
|
this.logFile = new File(file, str + ".txt");
|
|
this.mainThreadId = j;
|
|
}
|
|
|
|
public void collectLog(final String str, final String str2, final Throwable th, final ILogger.LEVEL level) {
|
|
final long currentTimeMillis = System.currentTimeMillis();
|
|
final long id = Thread.currentThread().getId();
|
|
if (this.fos == null) {
|
|
try {
|
|
this.fos = new FileOutputStream(this.logFile, true);
|
|
} catch (Exception e) {
|
|
Log.e("Heplshift_LogCollector", "Error opening debug log file: " + this.logFile.getAbsolutePath(), e);
|
|
return;
|
|
}
|
|
}
|
|
try {
|
|
this.executorService.submit(new Runnable() { // from class: com.helpshift.log.LogCollector.1
|
|
@Override // java.lang.Runnable
|
|
public void run() {
|
|
String stackTraceString;
|
|
try {
|
|
String format = LogCollector.this.dateFormat.format(new Date(currentTimeMillis));
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(format);
|
|
sb.append(" ");
|
|
sb.append(LogCollector.this.mainThreadId);
|
|
sb.append("-");
|
|
sb.append(id);
|
|
sb.append(" ");
|
|
sb.append(level.name());
|
|
sb.append("/");
|
|
sb.append(str);
|
|
sb.append(" ");
|
|
sb.append(str2);
|
|
Throwable th2 = th;
|
|
if (th2 instanceof UnknownHostException) {
|
|
stackTraceString = th2.getMessage();
|
|
} else {
|
|
stackTraceString = Log.getStackTraceString(th2);
|
|
}
|
|
if (!Utils.isEmpty(stackTraceString)) {
|
|
sb.append("\n");
|
|
sb.append(stackTraceString);
|
|
}
|
|
sb.append("\n");
|
|
LogCollector.this.fos.write(sb.toString().getBytes());
|
|
} catch (Exception e2) {
|
|
Log.e("Heplshift_LogCollector", "Error writing to debug log file", e2);
|
|
}
|
|
}
|
|
});
|
|
} catch (Exception e2) {
|
|
Log.e("Heplshift_LogCollector", "Error submitting to executor", e2);
|
|
}
|
|
}
|
|
|
|
public final void deleteOldFiles(File file) {
|
|
File[] listFiles = file.listFiles();
|
|
if (listFiles == null || listFiles.length <= 5) {
|
|
return;
|
|
}
|
|
Arrays.sort(listFiles);
|
|
for (int i = 0; i < listFiles.length - 5; i++) {
|
|
listFiles[i].delete();
|
|
}
|
|
}
|
|
}
|