Okhttp3Interceptor

class Okhttp3Interceptor(val logcat: LogCat) : Interceptor(source)

Log interceptor of Okhttp3.

// Add Interceptor
val logcat = logFactory("global")
val okhttp = OkHttpClient
.Builder()
.addInterceptor(Okhttp3Interceptor(logcat))
.build()

// Make a request
val request: Request = Request.Builder()
.url("http://127.0.0.1:7777")
.build()
okhttp.newCall(request).execute()

Since

1.3.3

See also

Constructors

Link copied to clipboard
constructor(logcat: LogCat)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Request body json converter.

Link copied to clipboard

Different levels represent different printing contents.

Link copied to clipboard
var filter: (Request) -> Boolean

The filter function allows you to filter log messages for requests matching the specified predicate. Return true directly by default.

Link copied to clipboard
private val logcat: LogCat
Link copied to clipboard
var requestLevel: (Request) -> LogLevel

The requestLevel function allows you to set the log level it prints based on Request, and returns LogLevel.DEBUG by default.

Link copied to clipboard
var responseLevel: (Response) -> LogLevel

The responseLevel function allows you to set the log level it prints based on Request, and returns LogLevel.DEBUG by default.

Link copied to clipboard

Functions

Link copied to clipboard
private fun StringBuilder.bodyToString(request: Request)

Convert Request.body to string.

Link copied to clipboard
private fun dealRequestLog(request: Request, connection: Connection?)

Deal request log.

Link copied to clipboard
private fun dealResponseLog(response: Response, tookMs: Long): Response

Deal response log.

Link copied to clipboard
open override fun intercept(chain: Interceptor.Chain): Response
Link copied to clipboard
fun sanitizedHeaders(header: String, replaceWith: String): Okhttp3Interceptor

Allows you to sanitize sensitive headers to avoid their values appearing in the logs. In the example below, Authorization header value will be replaced with '***' when logging: