Skip to content

Constructing a Store reconfigures the host app's global Kermit logger (drops its writers + tag) #749

Description

@epicadk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status
    🆕 Triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions