All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pandulapeter.beagle.logOkHttp.BeagleOkHttpLoggerImplementation.kt Maven / Gradle / Ivy

Go to download

A smart, reliable, and highly customizable debug menu library for Android apps that supports screen recording, network activity logging, and many other useful features.

There is a newer version: 2.9.7
Show 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
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy