Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A super tiny wrapper for Android Log utility.
@file:Suppress("unused")
package se.hellsoft.coroutineantipatterns
import android.util.Log
internal const val TAG = "KittyLog"
fun logi(message: String, throwable: Throwable? = null) {
try {
Log.i(TAG, message, throwable)
} catch (e: RuntimeException) {
if (e.message == "Stub!") {
// Safely ignore as we're running on host
} else {
throw e
}
}
}
fun logv(message: String, throwable: Throwable? = null) {
try {
Log.v(TAG, message, throwable)
} catch (e: RuntimeException) {
if (e.message == "Stub!") {
// Safely ignore as we're running on host
} else {
throw e
}
}
}
fun logd(message: String, throwable: Throwable? = null) {
try {
Log.d(TAG, message, throwable)
} catch (e: RuntimeException) {
if (e.message == "Stub!") {
// Safely ignore as we're running on host
} else {
throw e
}
}
}
fun logw(message: String, throwable: Throwable? = null) {
try {
Log.w(TAG, message, throwable)
} catch (e: RuntimeException) {
if (e.message == "Stub!") {
// Safely ignore as we're running on host
} else {
throw e
}
}
}
fun loge(message: String, throwable: Throwable? = null) {
try {
Log.e(TAG, message, throwable)
} catch (e: RuntimeException) {
if (e.message == "Stub!") {
// Safely ignore as we're running on host
} else {
throw e
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment