[6.4.0][全量日志] debug版本放开crash日志收集;触发全量日志上传时,附带将未上传的链路日志也打包上传
This commit is contained in:
@@ -225,7 +225,7 @@ ext {
|
||||
btrace : "com.bytedance.btrace:rhea-core:2.0.0",
|
||||
|
||||
mofang_runtime : "com.mogo.eagle.core.mofang:runtime:2.0.11",
|
||||
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.50",
|
||||
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.80",
|
||||
|
||||
// 安全证书
|
||||
passport_secret : "com.zhidaoauto:sdk-java:1.0.6-SNAPSHOT",
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.Manifest
|
||||
import android.content.*
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.os.Process
|
||||
import android.os.SystemClock
|
||||
import android.util.Log
|
||||
@@ -14,10 +15,13 @@ import com.mogo.commons.AbsMogoApplication
|
||||
import com.mogo.core.log.record.*
|
||||
import com.mogo.core.log.record.config.*
|
||||
import com.mogo.core.log.record.config.crash.CrashConfig
|
||||
import com.mogo.core.log.record.config.extra.IExtraFileToUpload
|
||||
import com.mogo.core.log.record.config.extra.ToUploadFile
|
||||
import com.mogo.core.log.record.config.state.IStateProvider
|
||||
import com.mogo.core.log.record.model.UploadError
|
||||
import com.mogo.eagle.core.data.app.AppConfigInfo
|
||||
import com.mogo.eagle.core.function.api.devatools.logcat.*
|
||||
import com.mogo.eagle.core.utilcode.download.DownloadUtils
|
||||
import com.zhidao.loglib.bean.RemoteLogPushContent
|
||||
import com.zhjt.mogo_core_function_devatools.BuildConfig
|
||||
import com.zhjt.mogo_core_function_devatools.logcat.checker.AnrLogChecker
|
||||
@@ -25,6 +29,7 @@ import com.zhjt.mogo_core_function_devatools.logcat.config.LogRecordConfig
|
||||
import com.zhjt.mogo_core_function_devatools.logcat.uploader.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.io.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeUnit.MINUTES
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
@@ -45,13 +50,12 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider,
|
||||
private val lastUploadTime by lazy { AtomicLong(0) }
|
||||
|
||||
override fun init(context: Context) {
|
||||
val zip = File(context.getExternalFilesDir(null), "logcat/zip")
|
||||
val builder = LogcatConfig.Builder().context(context)
|
||||
.recordPeriod(MINUTES.toMillis(5)) // 5分钟一个文件
|
||||
.maxSizeInLogDir((512 * 1024 * 1024).toLong()) // 512M最大容量
|
||||
.recordDir(File(context.getExternalFilesDir(null), "logcat"))
|
||||
.pid(Process.myPid())
|
||||
.generateZipDir(zip.absolutePath)
|
||||
.generateZipDir(File(context.getExternalFilesDir(null), "logcat/zip").absolutePath)
|
||||
.stateProvider(object : IStateProvider {
|
||||
override fun provide(divider: String?): Map<String, Any?> {
|
||||
return mutableMapOf<String, Any?>().also { itx ->
|
||||
@@ -104,6 +108,18 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider,
|
||||
itx["协议版本号"] = AppConfigInfo.protocolVersionNumber
|
||||
itx["${divider}-7"] = divider
|
||||
itx["角色"] = AppConfigInfo.role
|
||||
val downloads = try {
|
||||
DownloadUtils.getAllDownloadRecords()
|
||||
} catch (t: Throwable) {
|
||||
emptyList()
|
||||
}
|
||||
if (downloads.isNotEmpty()) {
|
||||
itx["${divider}-7"] = divider
|
||||
itx["下载汇总"] = "(${downloads.size})"
|
||||
downloads.forEach {
|
||||
itx[it.first] = "\n\r----------------------------------------------------------${it.second}\n\r"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -114,26 +130,26 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider,
|
||||
.systemTags("ActivityManager")
|
||||
.checker(AnrLogChecker())
|
||||
}
|
||||
|
||||
// if (BuildConfig.DEBUG) {
|
||||
// builder.crashConfig(
|
||||
// CrashConfig.Builder()
|
||||
// .enabled(true)
|
||||
// .crashDir(File(context.getExternalFilesDir(null), "logcat/crash"))
|
||||
// .nativeCrash(true)
|
||||
// .anr(true)
|
||||
// .javaCrash(true)
|
||||
// .build()
|
||||
// )
|
||||
// }
|
||||
if (BuildConfig.DEBUG) {
|
||||
builder.crashConfig(
|
||||
CrashConfig.Builder()
|
||||
.enabled(true)
|
||||
.crashDir(File(context.getExternalFilesDir(null), "crash"))
|
||||
.expireDuration(TimeUnit.DAYS.toMillis(3))
|
||||
.javaCrash(true)
|
||||
.nativeCrash(true)
|
||||
.anr(true)
|
||||
.build()
|
||||
)
|
||||
}
|
||||
builder.extraFilesToUpload(object : IExtraFileToUpload {
|
||||
override fun filesToUpload(): List<ToUploadFile> {
|
||||
return ArrayList<ToUploadFile>().also {
|
||||
it.add(ToUploadFile(File(Environment.getExternalStorageDirectory(), "MLog")))
|
||||
}
|
||||
}
|
||||
})
|
||||
LogcatManager.init(builder)
|
||||
scope.launch {
|
||||
try {
|
||||
zip.takeIf { it.exists() }?.deleteRecursively()
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun target(): Class<RemoteLogPushContent> {
|
||||
|
||||
@@ -84,4 +84,13 @@ object DownloadUtils {
|
||||
}
|
||||
.launchIn(scope)
|
||||
}
|
||||
|
||||
fun getAllDownloadRecords(): List<Pair<String, String>> {
|
||||
if (Downloader.hasInit()) {
|
||||
return runBlocking {
|
||||
Downloader.getAllDownloadRecords() ?: emptyList()
|
||||
}
|
||||
}
|
||||
return emptyList()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user