com.pandulapeter.beagle.logOkHttp.BeagleOkHttpLoggerImplementation.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of log-okhttp Show documentation
Show all versions of log-okhttp Show documentation
A smart, reliable, and highly customizable debug menu library for Android apps that supports screen recording, network activity logging, and many other useful features.
The newest version!
package com.pandulapeter.beagle.logOkHttp
import com.pandulapeter.beagle.commonBase.BeagleNetworkLoggerContract
import com.pandulapeter.beagle.commonBase.model.NetworkLogEntry
import okhttp3.Interceptor
internal class BeagleOkHttpLoggerImplementation : BeagleNetworkLoggerContract {
private var onNewLog: ((NetworkLogEntry) -> Unit)? = null
private var clearLogs: (() -> Unit)? = null
override val logger: Interceptor by lazy { OkHttpInterceptor() }
override fun logNetwork(
isOutgoing: Boolean,
url: String,
payload: String?,
headers: List?,
duration: Long?,
timestamp: Long,
id: String
) {
onNewLog?.invoke(
NetworkLogEntry(
id = id,
isOutgoing = isOutgoing,
url = url,
payload = payload,
headers = headers.orEmpty(),
duration = duration,
timestamp = timestamp,
)
)
}
override fun clearNetworkLogEntries() {
clearLogs?.invoke()
}
override fun register(
onNewLog: (NetworkLogEntry) -> Unit,
clearLogs: () -> Unit
) {
this.onNewLog = onNewLog
this.clearLogs = clearLogs
}
}