diff --git a/core/logging/config/build.gradle.kts b/core/logging/config/build.gradle.kts new file mode 100644 index 00000000000..b7eb7d8e07e --- /dev/null +++ b/core/logging/config/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + id(ThunderbirdPlugins.Library.kmp) +} + +android { + namespace = "net.thunderbird.core.logging.config" +} + +kotlin { + sourceSets { + androidMain.dependencies { + implementation(libs.timber) + } + commonMain.dependencies { + api(projects.core.logging.api) + implementation(projects.core.logging.implComposite) + implementation(projects.core.logging.implFile) + } + } +} diff --git a/core/logging/config/src/androidMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.android.kt b/core/logging/config/src/androidMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.android.kt new file mode 100644 index 00000000000..a2c1b59bf32 --- /dev/null +++ b/core/logging/config/src/androidMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.android.kt @@ -0,0 +1,12 @@ +package net.thunderbird.core.logging.config + +import timber.log.Timber + +actual class PlatformInitializer { + actual fun setUp(plantTimber: Boolean) { + Timber.uprootAll() + if (plantTimber) { + Timber.plant(Timber.DebugTree()) + } + } +} diff --git a/core/logging/impl-legacy/src/androidMain/kotlin/net/thunderbird/core/logging/legacy/DebugLogConfigurator.kt b/core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/DebugLogConfigurator.kt similarity index 66% rename from core/logging/impl-legacy/src/androidMain/kotlin/net/thunderbird/core/logging/legacy/DebugLogConfigurator.kt rename to core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/DebugLogConfigurator.kt index 2e8c63df314..45cfefba120 100644 --- a/core/logging/impl-legacy/src/androidMain/kotlin/net/thunderbird/core/logging/legacy/DebugLogConfigurator.kt +++ b/core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/DebugLogConfigurator.kt @@ -1,20 +1,15 @@ -package net.thunderbird.core.logging.legacy +package net.thunderbird.core.logging.config 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( private val syncDebugCompositeSink: CompositeLogSink, private val syncDebugFileLogSink: FileLogSink, + private val platformInitializer: PlatformInitializer, ) { fun updateLoggingStatus(isDebugLoggingEnabled: Boolean) { - Timber.uprootAll() - if (isDebugLoggingEnabled) { - Timber.plant(DebugTree()) - } + platformInitializer.setUp(isDebugLoggingEnabled) } fun updateSyncLogging(isSyncLoggingEnabled: Boolean) { diff --git a/core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.kt b/core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.kt new file mode 100644 index 00000000000..2e2297a58d2 --- /dev/null +++ b/core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.kt @@ -0,0 +1,5 @@ +package net.thunderbird.core.logging.config + +expect class PlatformInitializer { + fun setUp(plantTimber: Boolean) +} diff --git a/core/logging/config/src/jvmMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.jvm.kt b/core/logging/config/src/jvmMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.jvm.kt new file mode 100644 index 00000000000..5d982cd04c9 --- /dev/null +++ b/core/logging/config/src/jvmMain/kotlin/net/thunderbird/core/logging/config/PlatformInitializer.jvm.kt @@ -0,0 +1,7 @@ +package net.thunderbird.core.logging.config + +actual class PlatformInitializer { + actual fun setUp(plantTimber: Boolean) { + error("PlatformInitializer is not implemented for JVM platform") + } +} diff --git a/core/logging/impl-legacy/build.gradle.kts b/core/logging/impl-legacy/build.gradle.kts index c1c90701804..9548e37bbc2 100644 --- a/core/logging/impl-legacy/build.gradle.kts +++ b/core/logging/impl-legacy/build.gradle.kts @@ -12,6 +12,7 @@ kotlin { implementation(libs.timber) implementation(projects.core.logging.implComposite) implementation(projects.core.logging.implFile) + implementation(projects.core.logging.config) } commonMain.dependencies { diff --git a/legacy/core/build.gradle.kts b/legacy/core/build.gradle.kts index a9d4f9f1cd8..49b290b5879 100644 --- a/legacy/core/build.gradle.kts +++ b/legacy/core/build.gradle.kts @@ -14,6 +14,7 @@ dependencies { api(projects.core.android.logging) api(projects.core.logging.implFile) api(projects.core.logging.implComposite) + api(projects.core.logging.config) api(projects.core.android.network) api(projects.core.outcome) api(projects.feature.mail.folder.api) diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/DefaultGeneralSettingsManager.kt b/legacy/core/src/main/java/com/fsck/k9/preferences/DefaultGeneralSettingsManager.kt index c8a20f61eea..a8fc6c6791d 100644 --- a/legacy/core/src/main/java/com/fsck/k9/preferences/DefaultGeneralSettingsManager.kt +++ b/legacy/core/src/main/java/com/fsck/k9/preferences/DefaultGeneralSettingsManager.kt @@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Mutex import kotlinx.coroutines.sync.withLock -import net.thunderbird.core.logging.legacy.DebugLogConfigurator +import net.thunderbird.core.logging.config.DebugLogConfigurator import net.thunderbird.core.preference.GeneralSettings import net.thunderbird.core.preference.GeneralSettingsManager import net.thunderbird.core.preference.PreferenceChangePublisher diff --git a/legacy/core/src/main/java/com/fsck/k9/preferences/KoinModule.kt b/legacy/core/src/main/java/com/fsck/k9/preferences/KoinModule.kt index d9662b4fd17..bab0fd9ae3e 100644 --- a/legacy/core/src/main/java/com/fsck/k9/preferences/KoinModule.kt +++ b/legacy/core/src/main/java/com/fsck/k9/preferences/KoinModule.kt @@ -3,7 +3,8 @@ package com.fsck.k9.preferences import com.fsck.k9.Preferences import kotlin.time.ExperimentalTime import net.thunderbird.core.android.account.LegacyAccountDtoManager -import net.thunderbird.core.logging.legacy.DebugLogConfigurator +import net.thunderbird.core.logging.config.DebugLogConfigurator +import net.thunderbird.core.logging.config.PlatformInitializer import net.thunderbird.core.preference.DefaultPreferenceChangeBroker import net.thunderbird.core.preference.GeneralSettingsManager import net.thunderbird.core.preference.PreferenceChangeBroker @@ -119,10 +120,14 @@ val preferencesModule = module { logLevelManager = get(), ) } + single { + PlatformInitializer() + } single { DebugLogConfigurator( syncDebugCompositeSink = get(named("syncDebug")), syncDebugFileLogSink = get(named("syncDebug")), + platformInitializer = get(), ) } single { diff --git a/quality/konsist/src/test/kotlin/net/thunderbird/quality/ValidateLogger.kt b/quality/konsist/src/test/kotlin/net/thunderbird/quality/ValidateLogger.kt index 9e152bd05ef..2a0d3696135 100644 --- a/quality/konsist/src/test/kotlin/net/thunderbird/quality/ValidateLogger.kt +++ b/quality/konsist/src/test/kotlin/net/thunderbird/quality/ValidateLogger.kt @@ -27,10 +27,10 @@ class ValidateLogger { @Test fun `no class should use Timber logging`() { projectScope.files - .filterNot { it.hasNameMatching("ConsoleLogSink.android|ConsoleLogSinkTest.android".toRegex()) } + .filterNot { it.hasNameMatching("ConsoleLogSink.android|ConsoleLogSinkTest.android|PlatformInitializer.android".toRegex()) } .filterNot { // Exclude legacy code that still uses Timber - it.hasNameMatching("LogFileWriter|FileLoggerTree|K9|DebugLogConfigurator".toRegex()) + it.hasNameMatching("LogFileWriter|FileLoggerTree|K9".toRegex()) } .assertFalse( additionalMessage = "No class should use timber.log.Timber import, use net.thunderbird.core.logging.Logger instead." diff --git a/settings.gradle.kts b/settings.gradle.kts index 0e3a5216475..4492d603a3b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -153,6 +153,7 @@ include( ":core:configstore:impl-backend", ":core:featureflag", ":core:logging:api", + ":core:logging:config", ":core:logging:impl-composite", ":core:logging:impl-console", ":core:logging:impl-legacy",