Skip to content

Instantly share code, notes, and snippets.

@ErikHellman
Created August 19, 2019 09:19
Show Gist options
  • Save ErikHellman/38da213fef9b3bdb36421eca1ec715cd to your computer and use it in GitHub Desktop.
Save ErikHellman/38da213fef9b3bdb36421eca1ec715cd to your computer and use it in GitHub Desktop.
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