mirror of
https://github.com/yairm210/Unciv.git
synced 2025-02-20 19:56:51 +01:00
* Add simple logging solution * Fix Android compilation For some reason I stashed this and didn't unstash. * Add better logging explanation
36 lines
1005 B
Kotlin
36 lines
1005 B
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
|
|
}
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|