fix: stop Store from reconfiguring the host app's global Kermit logger - #750
Open
epicadk wants to merge 1 commit into
Open
fix: stop Store from reconfiguring the host app's global Kermit logger#750epicadk wants to merge 1 commit into
epicadk wants to merge 1 commit into
Conversation
…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
force-pushed
the
fix/global-kermit-logger-clobber
branch
from
July 26, 2026 13:02
1714ecd to
3bd7558
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #749
Problem
DefaultLoggerandRealStore's companion both run this onco.touchlab.kermit.Logger: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 viaaddLogWriter(...)(crash-reporter breadcrumbs, file writers).setTag("Store")overwrites the global default tag, so unrelated host logs start appearing underStore.withTagshares the sameMutableLoggerConfig, 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 +
minSeveritythe host configured, instead of replacing them. On a host that configured nothing, the sink falls back to Kermit'splatformLogWriter()(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-isolatedLogger(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, andspotlessare unaffected.Type of change
Bug fix (non-breaking).
Scope
Fix-only. The public
Loggerinterface is still only injectable through the internalRealMutableStoreconstructor — pre-existing and orthogonal to this bug. A publicloggerseam on the builders would be a natural follow-up; happy to do it as a separate PR.