Description
DefaultLogger and RealStore's companion object both run this on co.touchlab.kermit.Logger:
Logger.apply {
setLogWriters(listOf(CommonWriter()))
setTag("Store")
}
co.touchlab.kermit.Logger here is Kermit's process-global logger singleton, not a Store-scoped instance. So constructing a Store reconfigures logging for the entire host application:
setLogWriters(...) replaces the global writer list, dropping any LogWriter the host installed via Logger.addLogWriter(...) — e.g. a crash-reporter breadcrumb writer or a file writer.
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 rather than an edge case: hosts configure logging at startup and build Stores later, so Store construction silently wipes the host's logging setup — with no error.
Affected (both present on main and in 5.1.0-alpha06+):
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt (companion logger)
store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.kt
Expected
Instantiating a Store should not mutate the host application's global logging configuration.
Reproduction
Logger.addLogWriter(myCrashReporterWriter) // host setup at app startup
// ... later ...
StoreBuilder.from(fetcher).build() // constructs RealStore
// myCrashReporterWriter has now been removed from the global logger;
// the global default tag is now "Store".
Fix
Replace both sites with Logger.withTag("Store"), which derives a tagged logger sharing the host's config and mutates no global state. PR incoming.
Description
DefaultLoggerandRealStore's companion object both run this onco.touchlab.kermit.Logger:co.touchlab.kermit.Loggerhere is Kermit's process-global logger singleton, not a Store-scoped instance. So constructing a Store reconfigures logging for the entire host application:setLogWriters(...)replaces the global writer list, dropping anyLogWriterthe host installed viaLogger.addLogWriter(...)— e.g. a crash-reporter breadcrumb writer or a file writer.setTag("Store")overwrites the global default tag, so unrelated host logs start appearing under theStoretag.withTagshares the sameMutableLoggerConfig, loggers the host derived earlier are affected too.The usual ordering makes this the common case rather than an edge case: hosts configure logging at startup and build Stores later, so Store construction silently wipes the host's logging setup — with no error.
Affected (both present on
mainand in5.1.0-alpha06+):store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/RealStore.kt(companionlogger)store/src/commonMain/kotlin/org/mobilenativefoundation/store/store5/impl/DefaultLogger.ktExpected
Instantiating a Store should not mutate the host application's global logging configuration.
Reproduction
Fix
Replace both sites with
Logger.withTag("Store"), which derives a tagged logger sharing the host's config and mutates no global state. PR incoming.