Add network inspection logging mode
This commit is contained in:
parent
863e349711
commit
bfe67f1cdf
@ -265,7 +265,7 @@ dependencies {
|
|||||||
implementation 'com.lvla.android:rxjava2-interop-kt:0.2.1'
|
implementation 'com.lvla.android:rxjava2-interop-kt:0.2.1'
|
||||||
|
|
||||||
// Debug network interceptor (EH)
|
// Debug network interceptor (EH)
|
||||||
devImplementation "com.squareup.okhttp3:logging-interceptor:3.12.1"
|
implementation "com.squareup.okhttp3:logging-interceptor:3.12.1"
|
||||||
|
|
||||||
// Firebase (EH)
|
// Firebase (EH)
|
||||||
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
|
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
|
||||||
|
@ -24,6 +24,7 @@ import eu.kanade.tachiyomi.data.preference.getOrDefault
|
|||||||
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
import eu.kanade.tachiyomi.data.updater.UpdaterJob
|
||||||
import eu.kanade.tachiyomi.util.LocaleHelper
|
import eu.kanade.tachiyomi.util.LocaleHelper
|
||||||
import exh.log.CrashlyticsPrinter
|
import exh.log.CrashlyticsPrinter
|
||||||
|
import exh.log.EHLogLevel
|
||||||
import io.realm.Realm
|
import io.realm.Realm
|
||||||
import io.realm.RealmConfiguration
|
import io.realm.RealmConfiguration
|
||||||
import kotlinx.coroutines.GlobalScope
|
import kotlinx.coroutines.GlobalScope
|
||||||
@ -109,8 +110,7 @@ open class App : Application() {
|
|||||||
|
|
||||||
// EXH
|
// EXH
|
||||||
private fun setupExhLogging() {
|
private fun setupExhLogging() {
|
||||||
val logLevel = if(BuildConfig.DEBUG ||
|
val logLevel = if(BuildConfig.DEBUG || EHLogLevel.shouldLog(EHLogLevel.EXTRA)) {
|
||||||
Injekt.get<PreferencesHelper>().eh_detailedLogs().getOrDefault()) {
|
|
||||||
LogLevel.ALL
|
LogLevel.ALL
|
||||||
} else {
|
} else {
|
||||||
LogLevel.WARN
|
LogLevel.WARN
|
||||||
|
@ -183,5 +183,5 @@ object PreferenceKeys {
|
|||||||
|
|
||||||
const val eh_showTransitionPages = "eh_show_transition_pages"
|
const val eh_showTransitionPages = "eh_show_transition_pages"
|
||||||
|
|
||||||
const val eh_detailedLogs = "eh_detailed_logs"
|
const val eh_logLevel = "eh_log_level"
|
||||||
}
|
}
|
||||||
|
@ -256,5 +256,5 @@ class PreferencesHelper(val context: Context) {
|
|||||||
|
|
||||||
fun eh_showTransitionPages() = rxPrefs.getBoolean(Keys.eh_showTransitionPages, true)
|
fun eh_showTransitionPages() = rxPrefs.getBoolean(Keys.eh_showTransitionPages, true)
|
||||||
|
|
||||||
fun eh_detailedLogs() = rxPrefs.getBoolean(Keys.eh_detailedLogs, false)
|
fun eh_logLevel() = rxPrefs.getInteger(Keys.eh_logLevel, 0)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package eu.kanade.tachiyomi.network
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import exh.log.maybeInjectEHLogger
|
||||||
import okhttp3.*
|
import okhttp3.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
@ -25,6 +26,7 @@ class NetworkHelper(context: Context) {
|
|||||||
.cookieJar(cookieManager)
|
.cookieJar(cookieManager)
|
||||||
.cache(Cache(cacheDir, cacheSize))
|
.cache(Cache(cacheDir, cacheSize))
|
||||||
.enableTLS12()
|
.enableTLS12()
|
||||||
|
.maybeInjectEHLogger()
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
val cloudflareClient = client.newBuilder()
|
val cloudflareClient = client.newBuilder()
|
||||||
|
@ -22,6 +22,7 @@ import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
|||||||
import eu.kanade.tachiyomi.ui.library.LibraryController
|
import eu.kanade.tachiyomi.ui.library.LibraryController
|
||||||
import eu.kanade.tachiyomi.util.toast
|
import eu.kanade.tachiyomi.util.toast
|
||||||
import exh.debug.SettingsDebugController
|
import exh.debug.SettingsDebugController
|
||||||
|
import exh.log.EHLogLevel
|
||||||
import exh.ui.migration.MetadataFetchDialog
|
import exh.ui.migration.MetadataFetchDialog
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
import rx.android.schedulers.AndroidSchedulers
|
import rx.android.schedulers.AndroidSchedulers
|
||||||
@ -119,19 +120,17 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
summary = "Apply TachiyomiEH enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.joinToString { it.sourceName }}"
|
summary = "Apply TachiyomiEH enhancements to the following sources if they are installed: ${DELEGATED_SOURCES.values.joinToString { it.sourceName }}"
|
||||||
}
|
}
|
||||||
|
|
||||||
switchPreference {
|
intListPreference {
|
||||||
title = "Detailed logs"
|
key = PreferenceKeys.eh_logLevel
|
||||||
|
title = "Log level"
|
||||||
|
|
||||||
if(BuildConfig.DEBUG) {
|
entries = EHLogLevel.values().map {
|
||||||
summary = "Force-enabled in this debug build."
|
"${it.name.toLowerCase().capitalize()} (${it.description})"
|
||||||
isChecked = true
|
}.toTypedArray()
|
||||||
isPersistent = false
|
entryValues = EHLogLevel.values().mapIndexed { index, _ -> "$index" }.toTypedArray()
|
||||||
isEnabled = false
|
defaultValue = "0"
|
||||||
} else {
|
|
||||||
key = PreferenceKeys.eh_detailedLogs
|
summary = "Changing this can impact app performance. Force-restart app after changing. Current value: %s"
|
||||||
defaultValue = false
|
|
||||||
summary = "Increase detail level of logs. May cause the app to become slightly slower."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
preference {
|
preference {
|
||||||
|
22
app/src/main/java/exh/log/EHLogLevel.kt
Normal file
22
app/src/main/java/exh/log/EHLogLevel.kt
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
package exh.log
|
||||||
|
|
||||||
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import uy.kohesive.injekt.Injekt
|
||||||
|
import uy.kohesive.injekt.api.get
|
||||||
|
|
||||||
|
enum class EHLogLevel(val description: String) {
|
||||||
|
MINIMAL("critical errors only"),
|
||||||
|
EXTRA("log everything"),
|
||||||
|
EXTREME("network inspection mode");
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private val curLogLevel by lazy {
|
||||||
|
Injekt.get<PreferencesHelper>().eh_logLevel().getOrDefault()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun shouldLog(requiredLogLevel: EHLogLevel): Boolean {
|
||||||
|
return curLogLevel >= requiredLogLevel.ordinal
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
18
app/src/main/java/exh/log/EHNetworkLogging.kt
Normal file
18
app/src/main/java/exh/log/EHNetworkLogging.kt
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
package exh.log
|
||||||
|
|
||||||
|
import com.elvishew.xlog.XLog
|
||||||
|
import okhttp3.OkHttpClient
|
||||||
|
import okhttp3.logging.HttpLoggingInterceptor
|
||||||
|
|
||||||
|
fun OkHttpClient.Builder.maybeInjectEHLogger(): OkHttpClient.Builder {
|
||||||
|
if(EHLogLevel.shouldLog(EHLogLevel.EXTREME)) {
|
||||||
|
val xLogger = XLog.tag("EHNetwork")
|
||||||
|
.nst()
|
||||||
|
val interceptor = HttpLoggingInterceptor {
|
||||||
|
xLogger.d(it)
|
||||||
|
}
|
||||||
|
interceptor.level = HttpLoggingInterceptor.Level.BODY
|
||||||
|
return addInterceptor(interceptor)
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
@ -6,6 +6,7 @@ import eu.kanade.tachiyomi.source.online.all.EHentai
|
|||||||
import eu.kanade.tachiyomi.util.asJsoup
|
import eu.kanade.tachiyomi.util.asJsoup
|
||||||
import exh.EH_SOURCE_ID
|
import exh.EH_SOURCE_ID
|
||||||
import exh.EXH_SOURCE_ID
|
import exh.EXH_SOURCE_ID
|
||||||
|
import exh.log.maybeInjectEHLogger
|
||||||
import okhttp3.FormBody
|
import okhttp3.FormBody
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.Request
|
import okhttp3.Request
|
||||||
@ -16,7 +17,9 @@ class EHConfigurator {
|
|||||||
private val prefs: PreferencesHelper by injectLazy()
|
private val prefs: PreferencesHelper by injectLazy()
|
||||||
private val sources: SourceManager by injectLazy()
|
private val sources: SourceManager by injectLazy()
|
||||||
|
|
||||||
private val configuratorClient = OkHttpClient.Builder().build()
|
private val configuratorClient = OkHttpClient.Builder()
|
||||||
|
.maybeInjectEHLogger()
|
||||||
|
.build()
|
||||||
|
|
||||||
private fun EHentai.requestWithCreds(sp: Int = 1) = Request.Builder()
|
private fun EHentai.requestWithCreds(sp: Int = 1) = Request.Builder()
|
||||||
.addHeader("Cookie", cookiesHeader(sp))
|
.addHeader("Cookie", cookiesHeader(sp))
|
||||||
|
@ -26,6 +26,7 @@ import android.os.SystemClock
|
|||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
|
import exh.log.maybeInjectEHLogger
|
||||||
import exh.util.melt
|
import exh.util.melt
|
||||||
import rx.Observable
|
import rx.Observable
|
||||||
|
|
||||||
@ -33,7 +34,9 @@ class SolveCaptchaActivity : AppCompatActivity() {
|
|||||||
private val sourceManager: SourceManager by injectLazy()
|
private val sourceManager: SourceManager by injectLazy()
|
||||||
private val preferencesHelper: PreferencesHelper by injectLazy()
|
private val preferencesHelper: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
val httpClient = OkHttpClient()
|
val httpClient = OkHttpClient.Builder()
|
||||||
|
.maybeInjectEHLogger()
|
||||||
|
.build()
|
||||||
private val jsonParser = JsonParser()
|
private val jsonParser = JsonParser()
|
||||||
|
|
||||||
private var currentLoopId: String? = null
|
private var currentLoopId: String? = null
|
||||||
|
Loading…
x
Reference in New Issue
Block a user