refactoring logger
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
package ru.fincode.tsudesk.core.common.log
|
||||
|
||||
object Constants {
|
||||
const val LOG_DEBUG_TAG = "LOG_DEBUG_TAG"
|
||||
const val TAG = "DEBUG"
|
||||
}
|
||||
@@ -3,23 +3,21 @@ package ru.fincode.tsudesk.core.common.log
|
||||
import android.util.Log
|
||||
|
||||
private fun Any.moduleTag(): String {
|
||||
val module = this::class.java.`package`?.name?.substringAfterLast(".")?.uppercase() ?: "UNKNOWN"
|
||||
|
||||
return "${Constants.LOG_DEBUG_TAG}:$module"
|
||||
val pkg = this::class.java.`package`?.name.orEmpty()
|
||||
val parts = pkg.split('.')
|
||||
val module =
|
||||
if (parts.size >= 5 && parts[0] == "ru" && parts[1] == "fincode" && parts[2] == "tsudesk") {
|
||||
when (parts[3]) {
|
||||
"core", "feature" -> parts[4]
|
||||
else -> parts[3] // fallback
|
||||
}
|
||||
} else {
|
||||
parts.lastOrNull() ?: "unknown"
|
||||
}
|
||||
return "${Constants.TAG}:${module.uppercase()}"
|
||||
}
|
||||
|
||||
fun Any.logD(message: String) {
|
||||
Log.d(moduleTag(), message)
|
||||
}
|
||||
|
||||
fun Any.logD(message: String, throwable: Throwable) {
|
||||
Log.d(moduleTag(), message, throwable)
|
||||
}
|
||||
|
||||
fun Any.logE(message: String) {
|
||||
Log.e(moduleTag(), message)
|
||||
}
|
||||
|
||||
fun Any.logE(message: String, throwable: Throwable) {
|
||||
Log.e(moduleTag(), message, throwable)
|
||||
}
|
||||
fun Any.logD(message: String) = Log.d(moduleTag(), message)
|
||||
fun Any.logD(message: String, throwable: Throwable) = Log.d(moduleTag(), message, throwable)
|
||||
fun Any.logE(message: String) = Log.e(moduleTag(), message)
|
||||
fun Any.logE(message: String, throwable: Throwable) = Log.e(moduleTag(), message, throwable)
|
||||
|
||||
Reference in New Issue
Block a user