Skip to content

Commit

Permalink
Inject crash report logger from platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
prof18 committed Sep 13, 2024
1 parent 3e19997 commit 03e98a2
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 29 deletions.
1 change: 1 addition & 0 deletions androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ dependencies {

"googlePlayImplementation"(platform(libs.firebase.bom))
"googlePlayImplementation"(libs.firebase.crashlytics)
"googlePlayImplementation"(libs.touchlab.kermit.crash)

debugImplementation(compose.uiTooling)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.prof18.feedflow.android

import co.touchlab.kermit.LogWriter
import co.touchlab.kermit.Severity

class CrashlyticsHelper {
fun initCrashlytics() {
// no-op
}

fun crashReportingLogWriter(): LogWriter = object : LogWriter() {
override fun isLoggable(tag: String, severity: Severity): Boolean = false

override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
// no-op
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.prof18.feedflow.android

import co.touchlab.kermit.ExperimentalKermitApi
import co.touchlab.kermit.LogWriter
import co.touchlab.kermit.crashlytics.CrashlyticsLogWriter
import com.google.firebase.crashlytics.ktx.crashlytics
import com.google.firebase.ktx.Firebase
import com.prof18.feedflow.shared.utils.enableKmpCrashlytics
Expand All @@ -9,4 +12,7 @@ class CrashlyticsHelper {
Firebase.crashlytics.setCrashlyticsCollectionEnabled(true)
enableKmpCrashlytics()
}

@OptIn(ExperimentalKermitApi::class)
fun crashReportingLogWriter(): LogWriter = CrashlyticsLogWriter()
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class FeedFlowApp : Application() {
isDropboxSyncEnabled = isGooglePlayFlavor,
)

val crashlyticsHelper = CrashlyticsHelper()
if (isGooglePlayFlavor && appEnvironment.isRelease()) {
val crashlyticsHelper = CrashlyticsHelper()
crashlyticsHelper.initCrashlytics()
}

Expand All @@ -49,6 +49,7 @@ class FeedFlowApp : Application() {
platformSetup = {
workManagerFactory()
},
crashReportingLogWriter = crashlyticsHelper.crashReportingLogWriter(),
modules = listOf(
module {
single<Context> { this@FeedFlowApp }
Expand Down
7 changes: 1 addition & 6 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ kotlin {

val commonMobileMain by creating {
dependsOn(commonMain.get())

dependencies {
implementation(libs.crashk.ios)
implementation(libs.touchlab.kermit.crash)
}
}

androidMain {
Expand All @@ -113,7 +108,6 @@ kotlin {

dependencies {
implementation(libs.koin.android)
implementation(libs.crashk.ios)
implementation(libs.touchlab.kermit.crash)
implementation(libs.workmanager)
implementation(libs.koin.workmanager)
Expand All @@ -135,6 +129,7 @@ kotlin {

dependencies {
api(libs.touchlab.kermit.simple)
implementation(libs.touchlab.kermit.crash)
implementation(libs.ktor.client.darwin)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.prof18.feedflow.shared.di

import androidx.lifecycle.ViewModel
import co.touchlab.kermit.LogWriter
import co.touchlab.kermit.Logger
import co.touchlab.kermit.StaticConfig
import co.touchlab.kermit.platformLogWriter
Expand All @@ -24,7 +25,6 @@ import com.prof18.feedflow.shared.domain.feedsync.FeedSyncRepository
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncer
import com.prof18.feedflow.shared.domain.mappers.RssChannelMapper
import com.prof18.feedflow.shared.domain.settings.SettingsRepository
import com.prof18.feedflow.shared.logging.crashReportingLogWriter
import com.prof18.feedflow.shared.presentation.AccountsViewModel
import com.prof18.feedflow.shared.presentation.AddFeedViewModel
import com.prof18.feedflow.shared.presentation.FeedSourceListViewModel
Expand All @@ -49,6 +49,7 @@ import org.koin.dsl.module

fun initKoin(
appConfig: AppConfig,
crashReportingLogWriter: LogWriter,
modules: List<Module>,
platformSetup: KoinApplication.() -> Unit = {},
): KoinApplication {
Expand All @@ -57,19 +58,22 @@ fun initKoin(
modules +
coreModule +
dropboxModule +
getLoggingModule(appConfig) +
getLoggingModule(appConfig, crashReportingLogWriter) +
getPlatformModule(appConfig.appEnvironment) +
getFeedSyncModule(appConfig.appEnvironment),
)
platformSetup()
}
}

private fun getLoggingModule(appConfig: AppConfig): Module =
private fun getLoggingModule(
appConfig: AppConfig,
crashReportingLogWriter: LogWriter,
): Module =
module {
val loggers = mutableListOf(platformLogWriter())
if (appConfig.appEnvironment.isRelease() && appConfig.isLoggingEnabled) {
loggers.add(crashReportingLogWriter())
loggers.add(crashReportingLogWriter)
}

val baseLogger = Logger(
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.prof18.feedflow.shared.di

import app.cash.sqldelight.db.SqlDriver
import co.touchlab.kermit.ExperimentalKermitApi
import co.touchlab.kermit.Logger
import co.touchlab.kermit.crashlytics.CrashlyticsLogWriter
import com.prof18.feedflow.core.utils.AppConfig
import com.prof18.feedflow.core.utils.AppEnvironment
import com.prof18.feedflow.core.utils.DispatcherProvider
Expand Down Expand Up @@ -40,6 +42,7 @@ import org.koin.core.module.Module
import org.koin.core.parameter.parametersOf
import org.koin.dsl.module

@OptIn(ExperimentalKermitApi::class)
fun initKoinIos(
htmlParser: HtmlParser,
appEnvironment: AppEnvironment,
Expand All @@ -52,6 +55,7 @@ fun initKoinIos(
isLoggingEnabled = true,
isDropboxSyncEnabled = true,
),
crashReportingLogWriter = CrashlyticsLogWriter(),
modules = listOf(
module {
factory { htmlParser }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.prof18.feedflow.shared.domain.feedsync.FeedSyncJvmWorker
import com.prof18.feedflow.shared.domain.feedsync.FeedSyncWorker
import com.prof18.feedflow.shared.domain.model.CurrentOS
import com.prof18.feedflow.shared.domain.opml.OpmlFeedHandler
import com.prof18.feedflow.shared.logging.SentryLogWriter
import com.prof18.feedflow.shared.presentation.DropboxSyncViewModel
import com.russhwolf.settings.PreferencesSettings
import com.russhwolf.settings.Settings
Expand All @@ -32,6 +33,7 @@ fun initKoinDesktop(
isLoggingEnabled = true,
isDropboxSyncEnabled = true,
),
crashReportingLogWriter = SentryLogWriter(),
modules = modules + getDatabaseModule(appEnvironment),
)

Expand Down

This file was deleted.

0 comments on commit 03e98a2

Please sign in to comment.