1
0
mirror of https://github.com/ultrasonic/ultrasonic synced 2025-02-16 11:41:16 +01:00

Make full body logging an optional debug setting.

This commit is contained in:
tzugen 2022-04-07 15:14:14 +02:00
parent a98c9e2ffd
commit 5230ce011d
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
7 changed files with 28 additions and 6 deletions

View File

@ -34,7 +34,7 @@ private const val READ_TIMEOUT = 60_000L
*/
class SubsonicAPIClient(
config: SubsonicClientConfiguration,
private val okLogger: HttpLoggingInterceptor.Logger = HttpLoggingInterceptor.Logger.DEFAULT,
private val okLogger: HttpLoggingInterceptor,
baseOkClient: OkHttpClient = OkHttpClient.Builder().build()
) {
private val versionInterceptor = VersionInterceptor(config.minimalProtocolVersion)
@ -108,9 +108,7 @@ class SubsonicAPIClient(
val api: SubsonicAPIDefinition get() = wrappedApi
private fun OkHttpClient.Builder.addLogging() {
val loggingInterceptor = HttpLoggingInterceptor(okLogger)
loggingInterceptor.level = HttpLoggingInterceptor.Level.BODY
this.addInterceptor(loggingInterceptor)
this.addInterceptor(okLogger)
}
private fun OkHttpClient.Builder.allowSelfSignedCertificates() {

View File

@ -1,4 +1,5 @@
@file:JvmName("MusicServiceModule")
package org.moire.ultrasonic.di
import kotlin.math.abs
@ -22,6 +23,7 @@ import org.moire.ultrasonic.subsonic.ImageLoaderProvider
import org.moire.ultrasonic.subsonic.NetworkAndStorageChecker
import org.moire.ultrasonic.subsonic.ShareHandler
import org.moire.ultrasonic.util.Constants
import org.moire.ultrasonic.util.Settings
/**
* This Koin module contains the registration of classes related to the Music Services
@ -60,7 +62,16 @@ val musicServiceModule = module {
)
}
single<HttpLoggingInterceptor.Logger> { TimberOkHttpLogger() }
single<HttpLoggingInterceptor> {
val level = if (Settings.debugFullBody) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.HEADERS
}
HttpLoggingInterceptor(TimberOkHttpLogger())
.setLevel(level)
}
single { SubsonicAPIClient(get(), get()) }
single<MusicService>(named(ONLINE_MUSIC_SERVICE)) {

View File

@ -19,6 +19,7 @@ import java.io.IOException
import java.net.MalformedURLException
import java.net.URL
import java.util.Locale
import org.koin.android.ext.android.get
import org.koin.android.ext.android.inject
import org.koin.androidx.viewmodel.ext.android.viewModel
import org.moire.ultrasonic.BuildConfig
@ -408,7 +409,7 @@ class EditServerFragment : Fragment(), OnBackPressedHandler {
currentServerSetting!!.ldapSupport,
BuildConfig.DEBUG
)
val subsonicApiClient = SubsonicAPIClient(configuration)
val subsonicApiClient = SubsonicAPIClient(configuration, get())
// Execute a ping to retrieve the API version.
// This is accepted to fail if the authentication is incorrect yet.

View File

@ -108,6 +108,7 @@ object Constants {
const val PREFERENCES_KEY_CATEGORY_NOTIFICATIONS = "notificationsCategory"
const val PREFERENCES_KEY_FIRST_RUN_EXECUTED = "firstRunExecuted"
const val PREFERENCES_KEY_DEBUG_LOG_TO_FILE = "debugLogToFile"
const val PREFERENCES_KEY_DEBUG_LOG_BODY = "debugLogBody"
const val PREFERENCES_KEY_OVERRIDE_LANGUAGE = "overrideLanguage"
const val FILENAME_PLAYLIST_SER = "downloadstate.ser"
const val ALBUM_ART_FILE = "folder.jpeg"

View File

@ -234,6 +234,9 @@ object Settings {
@JvmStatic
var debugLogToFile by BooleanSetting(Constants.PREFERENCES_KEY_DEBUG_LOG_TO_FILE, false)
@JvmStatic
var debugFullBody by BooleanSetting(Constants.PREFERENCES_KEY_DEBUG_LOG_BODY, false)
@JvmStatic
val preferences: SharedPreferences
get() = PreferenceManager.getDefaultSharedPreferences(Util.appContext())

View File

@ -381,6 +381,8 @@
<string name="common_multiple_years">Multiple Years</string>
<string name="settings.debug.title">Debug options</string>
<string name="settings.debug.log_to_file">Write debug log to file</string>
<string name="settings.debug.log_body">Debug the body of HTTP calls</string>
<string name="settings.debug.log_body_summary">This will slow down streaming requests</string>
<string name="settings.debug.log_path">The log files are available at %1$s/%2$s</string>
<string name="settings.debug.log_summary">There are %1$s log files taking up ~%2$s MB space in the %3$s directory. Do you want to keep these?</string>
<string name="settings.debug.log_keep">Keep files</string>

View File

@ -341,6 +341,12 @@
a:title="@string/settings.debug.log_to_file"
a:summary=""
app:iconSpaceReserved="false"/>
<CheckBoxPreference
a:defaultValue="false"
a:key="debugLogBody"
a:title="@string/settings.debug.log_body"
a:summary="@string/settings.debug.log_body_summary"
app:iconSpaceReserved="false"/>
</PreferenceCategory>
</PreferenceScreen>