Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lutzifer/14363e65ff923024e417b27a9d7f671c to your computer and use it in GitHub Desktop.
Save Lutzifer/14363e65ff923024e417b27a9d7f671c to your computer and use it in GitHub Desktop.
RxKotlin Debug extension
import io.reactivex.rxjava3.core.Observable
import timber.log.Timber
fun <T : Any> Observable<T>.debug(customTag: String? = null): Observable<T> {
val fileTag = Exception().stackTrace[0].fileName
val tag = if (customTag == null) fileTag else "$fileTag - $customTag"
val line = Exception().stackTrace[0].lineNumber
return this
.doOnNext { item ->
Timber.tag(tag).d("[LINE $line] Next item: $item")
}.doOnComplete {
Timber.tag(tag).d("[LINE $line] Completed")
}.doOnError { error ->
Timber.tag(tag).d("[LINE $line] Error: $error")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment