RxJava+Kotlinでログを吐かせる便利拡張関数

fun <T> Observable<T>.logging(tag: String = Throwable().stackTrace[1].methodName): Observable<T> = this

.doOnSubscribe {
Log.d(tag, "doOnSubscribe")
}
.doOnNext {
Log.d(tag, "doOnNext = $it")
}
.doOnError {
Log.d(tag, "doOnError = $it")
}
.doOnComplete {
Log.d(tag, "doOnComplete")
}
.doOnDispose {
Log.d(tag, "doOnDispose")
}

使うとき

rxObject

.map { /* something to do */ }
.logging("rxObject")
.subscribeBy { /* something to do */ }

みたいにすれば、ログが吐かれる