From 3bd75581c219eb98bff2ab7d5b3a9e5cd42c55f2 Mon Sep 17 00:00:00 2001 From: Aditya Kurkure Date: Sun, 26 Jul 2026 17:02:27 +0530 Subject: [PATCH] fix: derive a tagged logger instead of reconfiguring Kermit's global logger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `DefaultLogger` and `RealStore`'s companion both ran `Logger.apply { setLogWriters(listOf(CommonWriter())); setTag("Store") }` on `co.touchlab.kermit.Logger`, which is Kermit's process-global logger singleton — not a Store-scoped instance. Constructing a Store therefore reconfigured logging for the entire host application: - `setLogWriters` replaces the global writer list, dropping any writer the host installed via `addLogWriter` (crash-reporter breadcrumbs, file writers). - `setTag("Store")` overwrites the global default tag, so unrelated host logs start appearing under the "Store" tag. - Because `withTag` shares the same `MutableLoggerConfig`, loggers the host derived earlier are affected too. The usual ordering makes this the common case: hosts configure logging at startup and build Stores later, so the Store construction silently wipes the host's logging setup with no error. Replace both sites with `Logger.withTag("Store")`, which derives a tagged logger sharing the host's config and mutates no global state. Store's logs now flow to whatever writers/severity the host configured; on an unconfigured host they fall back to Kermit's `platformLogWriter()` (Logcat/os_log/console/stdout), the conventional per-platform default. Co-Authored-By: Claude Signed-off-by: Aditya Kurkure --- .../store/store5/impl/DefaultLogger.kt | 10 ++++------ .../store/store5/impl/RealStore.kt | 9 +++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.kt index 9219683c3..1e25a050f 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.kt @@ -1,17 +1,15 @@ package org.mobilenativefoundation.store.store5.impl -import co.touchlab.kermit.CommonWriter import org.mobilenativefoundation.store.store5.Logger /** * Default implementation of [Logger] using the Kermit logging library. + * + * Derives a tagged logger from Kermit's global instance rather than reconfiguring it, so the host + * application's log writers and default tag are left untouched. */ internal class DefaultLogger : Logger { - private val delegate = - co.touchlab.kermit.Logger.apply { - setLogWriters(listOf(CommonWriter())) - setTag("Store") - } + private val delegate = co.touchlab.kermit.Logger.withTag("Store") override fun debug(message: String) { delegate.d(message) diff --git a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt index 632f339c8..4e9a0b16a 100644 --- a/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt +++ b/store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt @@ -15,7 +15,6 @@ */ package org.mobilenativefoundation.store.store5.impl -import co.touchlab.kermit.CommonWriter import co.touchlab.kermit.Logger import kotlinx.coroutines.CompletableDeferred import kotlinx.coroutines.CoroutineScope @@ -367,10 +366,8 @@ internal class RealStore( private fun fromMemCache(key: Key) = memCache?.getIfPresent(key) companion object { - private val logger = - Logger.apply { - setLogWriters(listOf(CommonWriter())) - setTag("Store") - } + // Derives a tagged logger instead of reconfiguring Kermit's global one, which would drop + // whatever log writers the host application installed. + private val logger = Logger.withTag("Store") } }