Un-break XLog network logging, code contributed from Neko
This commit is contained in:
parent
7ccaea0d72
commit
d3603a664c
@ -13,6 +13,7 @@ import eu.kanade.tachiyomi.source.model.MangasPage
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
import eu.kanade.tachiyomi.source.model.SChapter
|
||||
import eu.kanade.tachiyomi.source.model.SManga
|
||||
import exh.log.maybeInjectEHLogger
|
||||
import exh.patch.injectPatches
|
||||
import exh.source.DelegatedHttpSource
|
||||
import okhttp3.Headers
|
||||
@ -42,12 +43,14 @@ abstract class HttpSource : CatalogueSource {
|
||||
get() = delegate?.networkHttpClient ?: original.client
|
||||
.newBuilder()
|
||||
.injectPatches { id }
|
||||
.maybeInjectEHLogger()
|
||||
.build()
|
||||
|
||||
override val cloudflareClient: OkHttpClient
|
||||
get() = delegate?.networkCloudflareClient ?: original.cloudflareClient
|
||||
.newBuilder()
|
||||
.injectPatches { id }
|
||||
.maybeInjectEHLogger()
|
||||
.build()
|
||||
|
||||
override val cookieManager: AndroidCookieJar
|
||||
|
@ -1,16 +1,23 @@
|
||||
package exh.log
|
||||
|
||||
import com.elvishew.xlog.XLog
|
||||
import com.google.gson.Gson
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
|
||||
fun OkHttpClient.Builder.maybeInjectEHLogger(): OkHttpClient.Builder { // TODO - un-break this
|
||||
/* if(false &&EHLogLevel.shouldLog(EHLogLevel.EXTREME)) {
|
||||
val xLogger = XLog.tag("EHNetwork")
|
||||
.nst()
|
||||
val interceptor = HttpLoggingInterceptor {
|
||||
xLogger.d(it)
|
||||
fun OkHttpClient.Builder.maybeInjectEHLogger(): OkHttpClient.Builder {
|
||||
if (EHLogLevel.shouldLog(EHLogLevel.EXTREME)) {
|
||||
val logger: HttpLoggingInterceptor.Logger = object : HttpLoggingInterceptor.Logger {
|
||||
override fun log(message: String) {
|
||||
try {
|
||||
Gson().fromJson(message, Any::class.java)
|
||||
XLog.tag("||EH-NETWORK-JSON").nst().json(message)
|
||||
} catch (ex: Exception) {
|
||||
XLog.tag("||EH-NETWORK").nb().nst().d(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
interceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||
return addInterceptor(interceptor)
|
||||
} */
|
||||
return addInterceptor(HttpLoggingInterceptor(logger).apply { level = HttpLoggingInterceptor.Level.BODY })
|
||||
}
|
||||
return this
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user