A super tiny wrapper for Android Log utility that allows log printing in unit tests. For a more advanced log wrapper for Android, see https://github.com/JakeWharton/timber/
/* | |
Licensed under Apache 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
This is a tiny log utility for Android Logcat. It allows logs to be used in code that is unit | |
tested on host (without Android framework available). | |
The only advantage with this utility above Timber is that it doesn't require any setup. | |
For real-world, production application I strongly recommend using Timber (see https://github.com/JakeWharton/timber/) instead. | |
*/ | |
@file:Suppress("unused") | |
package se.hellsoft.kittlog | |
import android.util.Log | |
// TODO: Change this to whatever you want your logcat tag to be. | |
internal const val TAG = "KittyLog" | |
fun logi(message: String, throwable: Throwable? = null) { | |
try { | |
Log.i(TAG, message, throwable) | |
} catch (e: RuntimeException) { | |
println(message) | |
throwable?.printStackTrace() | |
} | |
} | |
fun logv(message: String, throwable: Throwable? = null) { | |
try { | |
Log.v(TAG, message, throwable) | |
} catch (e: RuntimeException) { | |
println(message) | |
throwable?.printStackTrace() | |
} | |
} | |
fun logd(message: String, throwable: Throwable? = null) { | |
try { | |
Log.d(TAG, message, throwable) | |
} catch (e: RuntimeException) { | |
println(message) | |
throwable?.printStackTrace() | |
} | |
} | |
fun logw(message: String, throwable: Throwable? = null) { | |
try { | |
Log.w(TAG, message, throwable) | |
} catch (e: RuntimeException) { | |
println(message) | |
throwable?.printStackTrace() | |
} | |
} | |
fun loge(message: String, throwable: Throwable? = null) { | |
try { | |
Log.e(TAG, message, throwable) | |
} catch (e: RuntimeException) { | |
println(message) | |
throwable?.printStackTrace() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment