[3.3.0][日志] 在调试面板添加导出全量日志入口
This commit is contained in:
@@ -219,7 +219,7 @@ ext {
|
||||
weak_network : "com.mogo.weak:network:1.0.0",
|
||||
|
||||
mofang_runtime : "com.mogo.eagle.core.mofang:runtime:2.0.5",
|
||||
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.0"
|
||||
log_runtime : "com.mogo.eagle.core.log.record:runtime:1.0.6"
|
||||
]
|
||||
android = [
|
||||
launcherApplicationId : "com.mogo.launcher",
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.os.Process
|
||||
import android.util.*
|
||||
import com.mogo.core.log.record.*
|
||||
import com.mogo.core.log.record.config.*
|
||||
import com.mogo.core.log.record.config.crash.*
|
||||
import com.mogo.eagle.core.function.api.devatools.logcat.*
|
||||
import com.mogo.eagle.core.utilcode.util.*
|
||||
import com.zhjt.mogo_core_function_devatools.logcat.uploader.*
|
||||
@@ -20,12 +21,31 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider {
|
||||
private val scope by lazy { CoroutineScope(Dispatchers.IO + SupervisorJob()) }
|
||||
|
||||
override fun init(context: Context) {
|
||||
val zipDir = File(context.getExternalFilesDir(null), "logcat/zip")
|
||||
LogcatManager.init(LogcatConfig.Builder().context(context)
|
||||
.recordPeriod(MINUTES.toMillis(3))
|
||||
.maxSizeInLogDir((1 * 1024 * 1024 * 1024).toLong()) //1G的最大容量
|
||||
.recordPeriod(MINUTES.toMillis(1)) // 1分钟一个文件
|
||||
.maxSizeInLogDir((512 * 1024 * 1024).toLong()) // 512M最大容量
|
||||
.recordDir(File(context.getExternalFilesDir(null), "logcat"))
|
||||
.pid(Process.myPid())
|
||||
.generateZipDir(zipDir.absolutePath)
|
||||
.crashConfig(CrashConfig.Builder()
|
||||
.enabled(true)
|
||||
.crashDir(File(context.getExternalFilesDir(null), "logcat/crash"))
|
||||
.javaCrash(true)
|
||||
.anr(true)
|
||||
.build())
|
||||
.uploader(LogRecordUploader()))
|
||||
scope.launch {
|
||||
try {
|
||||
if (zipDir.exists()) {
|
||||
zipDir.listFiles()?.forEach {
|
||||
it.delete()
|
||||
}
|
||||
}
|
||||
} catch (t: Throwable) {
|
||||
t.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,4 +71,8 @@ internal class MoGoLogRecordProviderImpl: IMoGoLogRecordProvider {
|
||||
Log.d(TAG, "上传日志:[startTime:$startTime, endTime: $endTime], 结果: $result")
|
||||
}
|
||||
}
|
||||
|
||||
override fun export(): File? {
|
||||
return LogcatManager.export()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,9 @@ import android.app.Activity
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
import android.net.*
|
||||
import android.os.Build
|
||||
import android.os.Process
|
||||
import android.text.Html
|
||||
@@ -16,6 +18,7 @@ import androidx.annotation.RequiresApi
|
||||
import androidx.appcompat.widget.PopupMenu
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.FileProvider
|
||||
import androidx.core.view.*
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import chassis.Chassis
|
||||
@@ -1363,6 +1366,38 @@ internal class DebugSettingView @JvmOverloads constructor(
|
||||
}
|
||||
}
|
||||
|
||||
//导出全量日志
|
||||
exportAllLogs?.onClick { v ->
|
||||
v.visibility = View.INVISIBLE
|
||||
logLoadingView?.visibility = View.VISIBLE
|
||||
v.scope.launch(Dispatchers.IO) {
|
||||
val file = CallerDevaToolsManager.logcat()?.export()
|
||||
if (file != null && file.exists()) {
|
||||
withContext(Dispatchers.Main) {
|
||||
var activity = AppStateManager.currentActivity()
|
||||
while (activity == null) {
|
||||
delay(2000)
|
||||
activity = AppStateManager.currentActivity()
|
||||
if (activity != null) {
|
||||
break
|
||||
}
|
||||
}
|
||||
activity?.startActivity(Intent.createChooser(Intent().also {
|
||||
it.action = Intent.ACTION_SEND
|
||||
it.type = "application/zip"
|
||||
it.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(activity, "${activity.packageName}.fileProvider", file))
|
||||
}, "分享全量日志压缩包到"))
|
||||
}
|
||||
} else {
|
||||
ToastUtils.showShort("全量日志压缩文件生成失败")
|
||||
}
|
||||
withContext(Dispatchers.Main) {
|
||||
logLoadingView?.visibility = View.INVISIBLE
|
||||
exportAllLogs?.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 展示、关闭日志过滤面板
|
||||
*/
|
||||
|
||||
@@ -2217,6 +2217,50 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_mf_sop_operator"
|
||||
android:paddingBottom="10dip"
|
||||
android:layout_marginStart="10dip"
|
||||
android:layout_marginEnd="10dip"
|
||||
android:paddingTop="10dip">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/logLoadingView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
android:visibility="invisible"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<TextView
|
||||
android:text="正在压缩全量日志,请稍候"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20dip"/>
|
||||
|
||||
<ProgressBar
|
||||
style="?android:attr/progressBarStyleSmall"
|
||||
android:layout_width="30dip"
|
||||
android:layout_height="30dip"
|
||||
android:layout_marginStart="10dip"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/exportAllLogs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="20dip"
|
||||
android:text="导出全量日志"
|
||||
android:gravity="center"
|
||||
android:layout_marginTop="10dip"
|
||||
android:layout_marginBottom="10dip" />
|
||||
</FrameLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.mogo.eagle.core.function.api.devatools.logcat
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
|
||||
interface IMoGoLogRecordProvider {
|
||||
|
||||
@@ -11,4 +12,6 @@ interface IMoGoLogRecordProvider {
|
||||
fun stop()
|
||||
|
||||
fun upload(startTime: Long, endTime: Long)
|
||||
|
||||
fun export(): File?
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import com.mogo.eagle.core.data.msgbox.MsgBoxBean
|
||||
import com.mogo.eagle.core.function.api.devatools.IDevaToolsProvider
|
||||
import com.mogo.eagle.core.function.api.devatools.apm.*
|
||||
import com.mogo.eagle.core.function.api.devatools.download.*
|
||||
import com.mogo.eagle.core.function.api.devatools.logcat.*
|
||||
import com.mogo.eagle.core.function.api.devatools.mofang.*
|
||||
import com.mogo.eagle.core.function.api.upgrade.*
|
||||
import com.mogo.eagle.core.function.api.devatools.strict.*
|
||||
@@ -261,4 +262,6 @@ object CallerDevaToolsManager {
|
||||
fun lookAroundProvider(): IMoGoLookAroundProvider? = devaToolsProviderApi?.lookAroundDataProvider()
|
||||
|
||||
fun mofang(): IMoGoMoFangProvider? = devaToolsProviderApi?.mofang()
|
||||
|
||||
fun logcat(): IMoGoLogRecordProvider? = devaToolsProviderApi?.logRecord()
|
||||
}
|
||||
@@ -2,4 +2,5 @@
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- Provides access to the installable APK in the package installer demo. -->
|
||||
<files-path name="all" path="." />
|
||||
<external-files-path name="all" path="." />
|
||||
</paths>
|
||||
Reference in New Issue
Block a user