Skip to content

Commit

Permalink
refactor LogUtils (#1643)
Browse files Browse the repository at this point in the history
Co-authored-by: roshan <[email protected]>
  • Loading branch information
dyeh123 and rrijal53 authored Oct 5, 2020
1 parent a1f4ac9 commit 5d8cd9e
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions app/src/main/kotlin/io/treehouses/remote/utils/LogUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ import io.treehouses.remote.BuildConfig

object LogUtils {
fun mOffline() {
if (BuildConfig.DEBUG) Log.e("STATUS", "OFFLINE")
logE("STATUS", "OFFLINE")
}

fun mIdle() {
if (BuildConfig.DEBUG) Log.e("STATUS", "IDLE")
logE("STATUS", "IDLE")
}

fun mConnect() {
if (BuildConfig.DEBUG) Log.e("STATUS", "CONNECTED")
logE("STATUS", "CONNECTED")
}

fun log(message: String?) {
if (BuildConfig.DEBUG) {
Log.d("TREEHOUSES ", message!!)
}
logD("TREEHOUSES", message!!)
}

fun writeMsg(msg: Message) {
Expand All @@ -39,9 +37,14 @@ fun Any.logE(msg: String, e: Throwable? = null) {


private fun logD(tag: String, msg: String) {
if (BuildConfig.DEBUG) Log.d(tag, msg)
log("d", tag, msg)
}

private fun logE(tag: String, msg: String) {
if (BuildConfig.DEBUG) Log.e(tag, msg)
log("e", tag, msg)
}

private fun log(type: String, tag: String, msg: String) {
if (BuildConfig.DEBUG)
Log::class.java.getMethod(type, String::class.java, String::class.java).invoke(null, tag, msg)
}

0 comments on commit 5d8cd9e

Please sign in to comment.