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

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

Merge pull request #9250 from wmontwe/add-logging

feat(core): Add logging KMP edition
parents acd57f2a a7302fda
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -17,6 +17,11 @@ dependencies {
    implementation(projects.legacy.core)
    implementation(projects.core.android.account)

    implementation(projects.core.logging.api)
    implementation(projects.core.logging.implComposite)
    implementation(projects.core.logging.implConsole)
    implementation(projects.core.logging.implLegacy)

    implementation(projects.core.featureflag)
    implementation(projects.core.ui.legacy.theme2.common)

+2 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import com.fsck.k9.legacyCommonAppModules
import com.fsck.k9.legacyCoreModules
import com.fsck.k9.legacyUiModules
import net.thunderbird.app.common.account.appCommonAccountModule
import net.thunderbird.app.common.core.appCommonCoreModule
import net.thunderbird.app.common.feature.appCommonFeatureModule
import org.koin.core.module.Module
import org.koin.dsl.module
@@ -15,6 +16,7 @@ val appCommonModule: Module = module {

    includes(
        appCommonAccountModule,
        appCommonCoreModule,
        appCommonFeatureModule,
    )
}
+6 −3
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ import com.fsck.k9.K9
import com.fsck.k9.MessagingListenerProvider
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.job.WorkManagerConfigurationProvider
import com.fsck.k9.logging.Timber
import com.fsck.k9.notification.NotificationChannelManager
import com.fsck.k9.ui.base.AppLanguageManager
import com.fsck.k9.ui.base.extensions.currentLocale
@@ -22,6 +21,8 @@ import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.drop
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import net.thunderbird.core.logging.Logger
import net.thunderbird.core.logging.legacy.Log
import net.thunderbird.core.ui.theme.manager.ThemeManager
import org.koin.android.ext.android.inject
import org.koin.core.module.Module
@@ -36,6 +37,7 @@ abstract class BaseApplication : Application(), WorkManagerConfiguration.Provide
    private val notificationChannelManager: NotificationChannelManager by inject()
    private val messageListWidgetManager: MessageListWidgetManager by inject()
    private val workManagerConfigurationProvider: WorkManagerConfigurationProvider by inject()
    private val logger: Logger by inject()

    private val appCoroutineScope: CoroutineScope = MainScope()
    private var appLanguageManagerInitialized = false
@@ -52,6 +54,7 @@ abstract class BaseApplication : Application(), WorkManagerConfiguration.Provide
    override fun onCreate() {
        super.onCreate()

        Log.logger = logger
        K9.init(this)
        Core.init(this)
        initializeAppLanguage()
@@ -95,7 +98,7 @@ abstract class BaseApplication : Application(), WorkManagerConfiguration.Provide
    }

    private fun updateConfigurationWithLocale(configuration: Configuration, locale: Locale) {
        Timber.d("Updating application configuration with locale '$locale'")
        Log.d("Updating application configuration with locale '$locale'")

        val newConfiguration = Configuration(configuration).apply {
            currentLocale = locale
@@ -119,7 +122,7 @@ abstract class BaseApplication : Application(), WorkManagerConfiguration.Provide
        if (appLanguageManagerInitialized) {
            appLanguageManager.getOverrideLocale()?.let { overrideLocale ->
                if (resources.configuration.currentLocale != overrideLocale) {
                    Timber.w("Resources configuration was reset. Re-applying locale override.")
                    Log.w("Resources configuration was reset. Re-applying locale override.")
                    appLanguageManager.applyOverrideLocale()
                    applyOverrideLocaleToConfiguration()
                }
+2 −2
Original line number Diff line number Diff line
@@ -10,7 +10,6 @@ import com.fsck.k9.Core
import com.fsck.k9.Preferences
import com.fsck.k9.account.DeletePolicyProvider
import com.fsck.k9.controller.MessagingController
import com.fsck.k9.logging.Timber
import com.fsck.k9.mail.ServerSettings
import com.fsck.k9.mail.store.imap.ImapStoreSettings.autoDetectNamespace
import com.fsck.k9.mail.store.imap.ImapStoreSettings.createExtra
@@ -24,6 +23,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import net.thunderbird.core.android.account.LegacyAccount
import net.thunderbird.core.common.mail.Protocols
import net.thunderbird.core.logging.legacy.Log
import net.thunderbird.feature.mail.folder.api.SpecialFolderSelection

// TODO Move to feature/account/setup
@@ -43,7 +43,7 @@ internal class AccountCreator(
        return try {
            withContext(coroutineDispatcher) { AccountCreatorResult.Success(create(account)) }
        } catch (e: Exception) {
            Timber.e(e, "Error while creating new account")
            Log.e(e, "Error while creating new account")

            AccountCreatorResult.Error(e.message ?: "Unknown create account error")
        }
+37 −0
Original line number Diff line number Diff line
package net.thunderbird.app.common.core

import net.thunderbird.core.logging.DefaultLogger
import net.thunderbird.core.logging.LogLevel
import net.thunderbird.core.logging.LogSink
import net.thunderbird.core.logging.Logger
import net.thunderbird.core.logging.composite.CompositeLogSink
import net.thunderbird.core.logging.console.ConsoleLogSink
import org.koin.core.module.Module
import org.koin.dsl.module

val appCommonCoreModule: Module = module {
    single<LogLevel> {
        LogLevel.INFO
    }

    single<List<LogSink>> {
        listOf(
            ConsoleLogSink(
                level = get(),
            ),
        )
    }

    single<LogSink> {
        CompositeLogSink(
            level = get(),
            sinks = get(),
        )
    }

    single<Logger> {
        DefaultLogger(
            sink = get(),
        )
    }
}
Loading