Files
Unciv/android/src/com/unciv/app/AndroidLogBackend.kt
vegeta1k95 494fde53cf Cleaning: platform specifics and UncivGame (#8773)
* Cleanup: platform specifics + UncivGame

* Fix tests

* Fix requests not clearing

---------

Co-authored-by: vegeta1k95 <vfylfhby>
2023-02-28 18:56:57 +02:00

43 lines
1.2 KiB
Kotlin

package com.unciv.app
import android.os.Build
import android.util.Log
import com.unciv.utils.LogBackend
import com.unciv.utils.Tag
private const val TAG_MAX_LENGTH = 23
class AndroidLogBackend : LogBackend {
override fun debug(tag: Tag, curThreadName: String, msg: String) {
Log.d(toAndroidTag(tag), "[$curThreadName] $msg")
}
override fun error(tag: Tag, curThreadName: String, msg: String) {
Log.e(toAndroidTag(tag), "[$curThreadName] $msg")
}
override fun isRelease(): Boolean {
return !BuildConfig.DEBUG
}
override fun getSystemInfo(): String {
return """
Device Model: ${Build.MODEL}
API Level: ${Build.VERSION.SDK_INT}
""".trimIndent()
}
}
private fun toAndroidTag(tag: Tag): String {
// This allows easy filtering of logcat by tag "Unciv"
val withUncivPrefix = if (tag.name.contains("unciv", true)) tag.name else "Unciv ${tag.name}"
// Limit was removed in Nougat
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N || tag.name.length <= TAG_MAX_LENGTH) {
withUncivPrefix
} else {
withUncivPrefix.substring(0, TAG_MAX_LENGTH)
}
}