diff options
author | Allan Wang <me@allanwang.ca> | 2017-12-31 02:44:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-31 02:44:46 -0500 |
commit | 725d6a99a07f91f940a07e6b49dd6224a6aa32d1 (patch) | |
tree | 4e0b1b3b9ffe9b5aef3c8d0f154ea9ab1058fd5e /app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt | |
parent | 3076d9a97c203497aec1415d8ac6037d10eebb46 (diff) | |
download | frost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.tar.gz frost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.tar.bz2 frost-725d6a99a07f91f940a07e6b49dd6224a6aa32d1.zip |
Enhancement/proguard (#589)
* Add error log
* Rewrite logger
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt')
-rw-r--r-- | app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt | 54 |
1 files changed, 47 insertions, 7 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt index d5c1a6fb..b4bed5e1 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/L.kt @@ -1,6 +1,6 @@ package com.pitchedapps.frost.utils -import ca.allanwang.kau.logging.KauLogger +import android.util.Log import com.crashlytics.android.Crashlytics import com.pitchedapps.frost.BuildConfig @@ -15,15 +15,55 @@ import com.pitchedapps.frost.BuildConfig * Debug and Error logs must not reveal person info * Person info logs can be marked as info or verbose */ -object L : KauLogger("Frost") { +object L { - override fun logImpl(priority: Int, message: String?, privateMessage: String?, t: Throwable?) { + const val TAG = "Frost" + + inline fun v(message: () -> Any?) { + if (BuildConfig.DEBUG) + logImpl(Log.VERBOSE, message) + } + + inline fun i(message: () -> Any?) { + logImpl(Log.INFO, message) + } + + inline fun _i(message: () -> Any?) { + if (BuildConfig.DEBUG) + logImpl(Log.INFO, message) + } + + inline fun d(message: () -> Any?) { + if (BuildConfig.DEBUG || Prefs.verboseLogging) + logImpl(Log.DEBUG, message) + } + + inline fun _d(message: () -> Any?) { + if (BuildConfig.DEBUG) + logImpl(Log.DEBUG, message) + } + + inline fun e(t: Throwable? = null, message: () -> Any?) { + logImpl(Log.ERROR, message, t) + } + + fun eThrow(message: Any) { + val msg = message.toString() + logImpl(Log.ERROR, { msg }, Throwable(msg)) + } + + inline fun logImpl(priority: Int, message: () -> Any?, t: Throwable? = null) { + val msg = message()?.toString() if (BuildConfig.DEBUG) { - super.logImpl(priority, message, privateMessage, t) + if (t != null) + Log.e(TAG, msg, t) + else + Log.println(priority, TAG, msg ?: "null") } else { - if (message != null) - Crashlytics.log(priority, "Frost", message) - if (t != null) Crashlytics.logException(t) + if (msg != null) + Crashlytics.log(priority, TAG, msg) + if (t != null) + Crashlytics.logException(t) } } }
\ No newline at end of file |