开发者
This commit is contained in:
parent
76b6a7eae2
commit
d74ae2f846
|
|
@ -127,33 +127,38 @@ object LogManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun zipLogs(context: Context): String? {
|
fun zipLogs(context: Context): String? {
|
||||||
val dir = logDir ?: return null
|
val zipFile = File(context.getExternalFilesDir(null), "full_logs_${System.currentTimeMillis()}.zip")
|
||||||
val zipFile = File(context.getExternalFilesDir(null), "logs_${System.currentTimeMillis()}.zip")
|
val logFolder = logDir // 这通常是 files/logs
|
||||||
val tombstoneDir = File(context.getExternalFilesDir(null), "tombstones")
|
val tombstoneFolder = File(context.getExternalFilesDir(null), "tombstones")
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
ZipOutputStream(FileOutputStream(zipFile)).use { zos ->
|
ZipOutputStream(FileOutputStream(zipFile)).use { zos ->
|
||||||
// 1. 打包普通日志
|
// 1. 打包 logs 文件夹
|
||||||
dir.listFiles()?.forEach { file ->
|
logFolder?.let { addFolderToZip(zos, it, "logs") }
|
||||||
if (file.isFile && (file.name.endsWith(".log") || file.name.endsWith(".txt"))) {
|
|
||||||
zos.putNextEntry(ZipEntry("logs/${file.name}"))
|
// 2. 打包 tombstones 文件夹
|
||||||
FileInputStream(file).use { it.copyTo(zos) }
|
if (tombstoneFolder.exists()) {
|
||||||
zos.closeEntry()
|
addFolderToZip(zos, tombstoneFolder, "tombstones")
|
||||||
}
|
|
||||||
}
|
|
||||||
// 2. 打包 Native 崩溃文件 (Tombstones)
|
|
||||||
if (tombstoneDir.exists()) {
|
|
||||||
tombstoneDir.listFiles()?.forEach { file ->
|
|
||||||
if (file.isFile) {
|
|
||||||
zos.putNextEntry(ZipEntry("native/${file.name}"))
|
|
||||||
FileInputStream(file).use { it.copyTo(zos) }
|
|
||||||
zos.closeEntry()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
zipFile.absolutePath
|
zipFile.absolutePath
|
||||||
} catch (e: Exception) { null }
|
} catch (e: Exception) {
|
||||||
|
android.util.Log.e("LogManager", "Zip failed", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun addFolderToZip(zos: ZipOutputStream, folder: File, parentName: String) {
|
||||||
|
folder.listFiles()?.forEach { file ->
|
||||||
|
if (file.isFile) {
|
||||||
|
try {
|
||||||
|
val entry = ZipEntry("$parentName/${file.name}")
|
||||||
|
zos.putNextEntry(entry)
|
||||||
|
FileInputStream(file).use { it.copyTo(zos) }
|
||||||
|
zos.closeEntry()
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun uploadLogs(context: Context, callback: (Boolean, String) -> Unit) {
|
fun uploadLogs(context: Context, callback: (Boolean, String) -> Unit) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue