Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 573d5f66 authored by Wolf-Martell Montwé's avatar Wolf-Martell Montwé Committed by GitHub
Browse files

Merge pull request #9514 from shamim-emon/fix-issue-9511

Migrate K9.isSyncLoggingEnabled to PreferenceDataStore
parents b4ce8adb 2ab92ff9
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ kotlin {
    sourceSets {
        androidMain.dependencies {
            implementation(libs.timber)
            implementation(projects.core.logging.implComposite)
            implementation(projects.core.logging.implFile)
        }

        commonMain.dependencies {
+16 −3
Original line number Diff line number Diff line
package net.thunderbird.core.logging.legacy

import net.thunderbird.core.logging.composite.CompositeLogSink
import net.thunderbird.core.logging.file.FileLogSink
import timber.log.Timber
import timber.log.Timber.DebugTree

// TODO: Implementation https://github.com/thunderbird/thunderbird-android/issues/9573
class DebugLogConfigurator {

class DebugLogConfigurator(
    private val syncDebugCompositeSink: CompositeLogSink,
    private val syncDebugFileLogSink: FileLogSink,
) {
    fun updateLoggingStatus(isDebugLoggingEnabled: Boolean) {
        Timber.uprootAll()
        if (isDebugLoggingEnabled) {
            Timber.plant(Timber.DebugTree())
            Timber.plant(DebugTree())
        }
    }

    fun updateSyncLogging(isSyncLoggingEnabled: Boolean) {
        if (isSyncLoggingEnabled) {
            syncDebugCompositeSink.manager.add(syncDebugFileLogSink)
        } else {
            syncDebugCompositeSink.manager.remove(syncDebugFileLogSink)
        }
    }
}
+2 −0
Original line number Diff line number Diff line
package net.thunderbird.core.preference.debugging

const val DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED = false
val DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED = isDebug

data class DebuggingSettings(
    val isDebugLoggingEnabled: Boolean = DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED,
    val isSyncLoggingEnabled: Boolean = DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED,
)
+1 −0
Original line number Diff line number Diff line
@@ -3,5 +3,6 @@ package net.thunderbird.core.preference.debugging
import net.thunderbird.core.preference.PreferenceManager

const val KEY_ENABLE_DEBUG_LOGGING = "enableDebugLogging"
const val KEY_ENABLE_SYNC_DEBUG_LOGGING = "enableSyncDebugLogging"

interface DebuggingSettingsPreferenceManager : PreferenceManager<DebuggingSettings>
+5 −0
Original line number Diff line number Diff line
@@ -40,6 +40,10 @@ class DefaultDebuggingSettingsPreferenceManager(
            KEY_ENABLE_DEBUG_LOGGING,
            DEBUGGING_SETTINGS_DEFAULT_IS_DEBUGGING_LOGGING_ENABLED,
        ),
        isSyncLoggingEnabled = storage.getBoolean(
            KEY_ENABLE_SYNC_DEBUG_LOGGING,
            DEBUGGING_SETTINGS_DEFAULT_IS_SYNC_LOGGING_ENABLED,
        ),
    )

    private fun writeConfig(config: DebuggingSettings) {
@@ -47,6 +51,7 @@ class DefaultDebuggingSettingsPreferenceManager(
        scope.launch(ioDispatcher) {
            mutex.withLock {
                storageEditor.putBoolean(KEY_ENABLE_DEBUG_LOGGING, config.isDebugLoggingEnabled)
                storageEditor.putBoolean(KEY_ENABLE_SYNC_DEBUG_LOGGING, config.isSyncLoggingEnabled)
                storageEditor.commit().also { commited ->
                    logger.verbose(TAG) { "writeConfig: storageEditor.commit() resulted in: $commited" }
                }
Loading