Skip to content

fix: stop Store from reconfiguring the host app's global Kermit logger - #750

Open
epicadk wants to merge 1 commit into
MobileNativeFoundation:mainfrom
epicadk:fix/global-kermit-logger-clobber
Open

fix: stop Store from reconfiguring the host app's global Kermit logger#750
epicadk wants to merge 1 commit into
MobileNativeFoundation:mainfrom
epicadk:fix/global-kermit-logger-clobber

Conversation

@epicadk

@epicadk epicadk commented Jul 26, 2026

Copy link
Copy Markdown

Closes #749

Problem

DefaultLogger and RealStore's companion both run this on co.touchlab.kermit.Logger:

Logger.apply {
    setLogWriters(listOf(CommonWriter()))
    setTag("Store")
}

That receiver is Kermit's process-global logger singleton, not a Store-scoped instance. So constructing a Store reconfigures logging for the whole host app:

  • 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 Store.
  • Because withTag shares the same MutableLoggerConfig, loggers the host derived earlier are affected too.

Hosts configure logging at startup and build Stores later, so this is the common ordering — Store construction silently wipes the host's logging setup, with no error.

Fix

Replace both sites with Logger.withTag("Store") — Kermit's recommended way to make a tagged logger. It derives a logger sharing the host's config and mutates no global state.

Intended behavior change (not a regression): Store now routes its internal logs through whatever writers + minSeverity the host configured, instead of replacing them. On a host that configured nothing, the sink falls back to Kermit's platformLogWriter() (Logcat / os_log / console.* / stdout+stderr) — the conventional per-platform default. Sharing host config is the deliberate good-citizen choice so the host can route or silence Store's logs; the fully-isolated Logger(loggerConfigInit(platformLogWriter()), "Store") was the consciously-rejected alternative.

The change is a behavior-preserving swap to a documented Kermit API touching only internal classes; apiCheck (JVM + KLib ABI), ktlint, and spotless are unaffected.

Type of change

Bug fix (non-breaking).

Scope

Fix-only. The public Logger interface is still only injectable through the internal RealMutableStore constructor — pre-existing and orthogonal to this bug. A public logger seam on the builders would be a natural follow-up; happy to do it as a separate PR.

…logger

`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 <noreply@anthropic.com>
Signed-off-by: Aditya Kurkure <adityakurkure@gmail.com>
@epicadk
epicadk force-pushed the fix/global-kermit-logger-clobber branch from 1714ecd to 3bd7558 Compare July 26, 2026 13:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🆕 Triage

Development

Successfully merging this pull request may close these issues.

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

1 participant