Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions core/logging/config/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
Original file line number Diff line number Diff line change
@@ -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())
}
}
}
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package net.thunderbird.core.logging.config

expect class PlatformInitializer {
fun setUp(plantTimber: Boolean)
}
Original file line number Diff line number Diff line change
@@ -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")
}
}
1 change: 1 addition & 0 deletions core/logging/impl-legacy/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions legacy/core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,10 +120,14 @@ val preferencesModule = module {
logLevelManager = get(),
)
}
single<PlatformInitializer> {
PlatformInitializer()
}
single<DebugLogConfigurator> {
DebugLogConfigurator(
syncDebugCompositeSink = get(named("syncDebug")),
syncDebugFileLogSink = get(named("syncDebug")),
platformInitializer = get(),
)
}
single {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading