Skip to content

Commit

Permalink
保存日志文件时写入设备信息
Browse files Browse the repository at this point in the history
  • Loading branch information
aaa1115910 committed Aug 17, 2024
1 parent 34a9002 commit 526a1a1
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions app/src/main/kotlin/dev/aaa1115910/bv/util/LogCatcherUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
import java.io.BufferedReader
import java.io.File
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.text.SimpleDateFormat
import java.util.Date
import java.util.Locale
Expand Down Expand Up @@ -45,6 +46,9 @@ object LogCatcherUtil {
logger.info { "Log file: $logFile" }

with(logFile.writer()) {
writeDeviceInfo()
writeAppInfo()
appendLine("======== Logs ========")
var line: String?
while (reader.readLine().also { line = it } != null) {
appendLine(line)
Expand All @@ -58,6 +62,31 @@ object LogCatcherUtil {
}
}

private fun OutputStreamWriter.writeDeviceInfo() {
val info = BVApp.context.packageManager.getPackageInfo(BVApp.context.packageName, 0)
appendLine("======== Device info ========")
appendLine("App Version: ${info.versionName} (${info.versionCode})")
appendLine("Android Version: ${android.os.Build.VERSION.RELEASE} (${android.os.Build.VERSION.SDK_INT})")
appendLine("Device: ${android.os.Build.DEVICE}")
appendLine("Model: ${android.os.Build.MODEL}")
appendLine("Manufacturer: ${android.os.Build.MANUFACTURER}")
appendLine("Brand: ${android.os.Build.BRAND}")
appendLine("Product: ${android.os.Build.PRODUCT}")
appendLine("Type: ${android.os.Build.TYPE}")
}

private fun OutputStreamWriter.writeAppInfo() {
appendLine("======== App Prefs ========")
appendLine("Login: ${Prefs.isLogin}")
appendLine("Incognito Mode: ${Prefs.incognitoMode}")
appendLine("Api Type: ${Prefs.apiType.name}")
appendLine("Default Resolution: ${Prefs.defaultQuality}")
appendLine("Default Codec: ${Prefs.defaultVideoCodec.name}")
appendLine("Default Audio: ${Prefs.defaultAudio.name}")
appendLine("Enabled Proxy: ${Prefs.enableProxy}")
appendLine("Using Old Player: ${Prefs.useOldPlayer}")
}

private fun createFilename(manual: Boolean): String {
var filename = ""
filename += if (manual) MANUAL_LOG_PREFIX else CRASH_LOG_PREFIX
Expand Down

0 comments on commit 526a1a1

Please sign in to comment.