Created
August 19, 2019 09:19
-
-
Save ErikHellman/38da213fef9b3bdb36421eca1ec715cd to your computer and use it in GitHub Desktop.
A super tiny wrapper for Android Log utility.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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