Hello guys! Can someone explain me why extension f...
# android
s
Hello guys! Can someone explain me why extension function not working with Log class or Crashlytics?
Copy code
fun Log.dd(msg: String? = "null", tag: String = "test1") = Log.d(tag, msg)
r
They dont work with statics
👍 1
s
Thanks! They really have private constructor with no chance to create instance.
r
did you mean msg: String? = null
or msg: String? = "null"
s
@Rajkumar Singh, it's just example. I realize 2 extensions, this:
Copy code
fun Any.logE(msg: String, tr: Throwable? = null, tag: String = "test1") = when (tr) {
    null -> Log.e(tag, msg)
    else -> Log.e(tag, msg, tr)
}
And this:
Copy code
fun Any.crashlyticsLog(tr: Throwable, msg: String): Unit {
    logE(msg, tr)
    Crashlytics.log(msg)
    Crashlytics.logException(tr)
}
So i can log errors to Logcat and report to crashlytics in one line. For example:
Copy code
try {
    //Do something
} catch(e: Exception) {
    crashlyticsLog(e, "some info")
}
p
@STAYER you need to take a look into Timber library. It's built for that
👍 1
s
@pavi2410 yep, i use Timber in new project, and it is nice)
p
Great to know that