Skip to content

Commit 3b78eb2

Browse files
authored
Merge pull request #9863 from shamim-emon/fix-issue-9573
Migrate DebugLogConfigurator to Use New Logger Infrastructure and Isolate from Timber, While Supporting Timber Setup in Android Module
2 parents ca08d0c + d46c446 commit 3b78eb2

11 files changed

Lines changed: 59 additions & 12 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
plugins {
2+
id(ThunderbirdPlugins.Library.kmp)
3+
}
4+
5+
android {
6+
namespace = "net.thunderbird.core.logging.config"
7+
}
8+
9+
kotlin {
10+
sourceSets {
11+
androidMain.dependencies {
12+
implementation(libs.timber)
13+
}
14+
commonMain.dependencies {
15+
api(projects.core.logging.api)
16+
implementation(projects.core.logging.implComposite)
17+
implementation(projects.core.logging.implFile)
18+
}
19+
}
20+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package net.thunderbird.core.logging.config
2+
3+
import timber.log.Timber
4+
5+
actual class PlatformInitializer {
6+
actual fun setUp(plantTimber: Boolean) {
7+
Timber.uprootAll()
8+
if (plantTimber) {
9+
Timber.plant(Timber.DebugTree())
10+
}
11+
}
12+
}

core/logging/impl-legacy/src/androidMain/kotlin/net/thunderbird/core/logging/legacy/DebugLogConfigurator.kt renamed to core/logging/config/src/commonMain/kotlin/net/thunderbird/core/logging/config/DebugLogConfigurator.kt

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1-
package net.thunderbird.core.logging.legacy
1+
package net.thunderbird.core.logging.config
22

33
import net.thunderbird.core.logging.composite.CompositeLogSink
44
import net.thunderbird.core.logging.file.FileLogSink
5-
import timber.log.Timber
6-
import timber.log.Timber.DebugTree
75

8-
// TODO: Implementation https://github.com/thunderbird/thunderbird-android/issues/9573
96
class DebugLogConfigurator(
107
private val syncDebugCompositeSink: CompositeLogSink,
118
private val syncDebugFileLogSink: FileLogSink,
9+
private val platformInitializer: PlatformInitializer,
1210
) {
1311
fun updateLoggingStatus(isDebugLoggingEnabled: Boolean) {
14-
Timber.uprootAll()
15-
if (isDebugLoggingEnabled) {
16-
Timber.plant(DebugTree())
17-
}
12+
platformInitializer.setUp(isDebugLoggingEnabled)
1813
}
1914

2015
fun updateSyncLogging(isSyncLoggingEnabled: Boolean) {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package net.thunderbird.core.logging.config
2+
3+
expect class PlatformInitializer {
4+
fun setUp(plantTimber: Boolean)
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package net.thunderbird.core.logging.config
2+
3+
actual class PlatformInitializer {
4+
actual fun setUp(plantTimber: Boolean) {
5+
error("PlatformInitializer is not implemented for JVM platform")
6+
}
7+
}

core/logging/impl-legacy/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ kotlin {
1212
implementation(libs.timber)
1313
implementation(projects.core.logging.implComposite)
1414
implementation(projects.core.logging.implFile)
15+
implementation(projects.core.logging.config)
1516
}
1617

1718
commonMain.dependencies {

legacy/core/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
api(projects.core.android.logging)
1515
api(projects.core.logging.implFile)
1616
api(projects.core.logging.implComposite)
17+
api(projects.core.logging.config)
1718
api(projects.core.android.network)
1819
api(projects.core.outcome)
1920
api(projects.feature.mail.folder.api)

legacy/core/src/main/java/com/fsck/k9/preferences/DefaultGeneralSettingsManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.flow.stateIn
1313
import kotlinx.coroutines.launch
1414
import kotlinx.coroutines.sync.Mutex
1515
import kotlinx.coroutines.sync.withLock
16-
import net.thunderbird.core.logging.legacy.DebugLogConfigurator
16+
import net.thunderbird.core.logging.config.DebugLogConfigurator
1717
import net.thunderbird.core.preference.GeneralSettings
1818
import net.thunderbird.core.preference.GeneralSettingsManager
1919
import net.thunderbird.core.preference.PreferenceChangePublisher

legacy/core/src/main/java/com/fsck/k9/preferences/KoinModule.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package com.fsck.k9.preferences
33
import com.fsck.k9.Preferences
44
import kotlin.time.ExperimentalTime
55
import net.thunderbird.core.android.account.LegacyAccountDtoManager
6-
import net.thunderbird.core.logging.legacy.DebugLogConfigurator
6+
import net.thunderbird.core.logging.config.DebugLogConfigurator
7+
import net.thunderbird.core.logging.config.PlatformInitializer
78
import net.thunderbird.core.preference.DefaultPreferenceChangeBroker
89
import net.thunderbird.core.preference.GeneralSettingsManager
910
import net.thunderbird.core.preference.PreferenceChangeBroker
@@ -119,10 +120,14 @@ val preferencesModule = module {
119120
logLevelManager = get(),
120121
)
121122
}
123+
single<PlatformInitializer> {
124+
PlatformInitializer()
125+
}
122126
single<DebugLogConfigurator> {
123127
DebugLogConfigurator(
124128
syncDebugCompositeSink = get(named("syncDebug")),
125129
syncDebugFileLogSink = get(named("syncDebug")),
130+
platformInitializer = get(),
126131
)
127132
}
128133
single {

quality/konsist/src/test/kotlin/net/thunderbird/quality/ValidateLogger.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ class ValidateLogger {
2727
@Test
2828
fun `no class should use Timber logging`() {
2929
projectScope.files
30-
.filterNot { it.hasNameMatching("ConsoleLogSink.android|ConsoleLogSinkTest.android".toRegex()) }
30+
.filterNot { it.hasNameMatching("ConsoleLogSink.android|ConsoleLogSinkTest.android|PlatformInitializer.android".toRegex()) }
3131
.filterNot {
3232
// Exclude legacy code that still uses Timber
33-
it.hasNameMatching("LogFileWriter|FileLoggerTree|K9|DebugLogConfigurator".toRegex())
33+
it.hasNameMatching("LogFileWriter|FileLoggerTree|K9".toRegex())
3434
}
3535
.assertFalse(
3636
additionalMessage = "No class should use timber.log.Timber import, use net.thunderbird.core.logging.Logger instead."

0 commit comments

Comments
 (0)