Regarding the use of `Kermit` in `KaMPKit`: I can ...
# touchlab-tools
m
Regarding the use of
Kermit
in `KaMPKit`: I can see that a logger instance is created for every location where it’s being used (https://github.com/touchlab/KaMPKit/blob/main/shared/src/commonMain/kotlin/co/touchlab/kampkit/Koin.kt#L63). Is this simply for the
tag
? If there’s no need to switch tags, then is there any upside to injecting
Logger
vs just calling the static methods like
Logger.i { "something" }
k
It's for tags, as you suspect. The general Android "pattern" is having a static
TAG = "NameOfTheClassImIn"
everywhere, so it's an alternative to that. There is no logical benefit of injected vs global if you aren't localizing tags. There is some performance benefit, presumably, as you can have immutable config. All global access goes through some form of concurrent-safe instance access. That means volatile on JVM and an atomic on native (old or new memory model). It's not something I'd worry about in most cases, but as a "logging library publisher" we went a little deep on these considerations.
👍 1
m
Thanks for the clarification! I was looking into using Kermit and the pattern in KaMPKit felt a bit unfamiliar coming from Timber/Log. A follow up question regarding the global: is there any recommended way in providing the config? I set up my own log writer but ended up with a crash on iOS (AtomicReference).
k
the pattern in KaMPKit felt a bit unfamiliar coming from Timber/Log
The tag thing is really an android thing, and while I'm used to it after the years of Android, when you step back and look at it, it's kind of weird (to me) to need to pass in a tag for every log call. The kermit pattern lets you do that, or just config the tag once and use the same instance everywhere.
On "recommended way in providing the config?", I'm not sure what you mean. What kind of crash? You shouldn't get crashes, obviously. For global config, just call that on app start. I usually create a helper function in
iosMain
that gets called from the iOS app's AppDelegate on startup.
m
Thanks again for the replies and clarifying.
On “recommended way in providing the config?“, I’m not sure what you mean
I was referring what you were mentioned, which is, for example, the helper function on
iosMain
.
What kind of crash? You shouldn’t get crashes, obviously
Probably something wrong with my own logic here to be honest
Copy code
internal val loggerModule = module {
    val debug = Config.isDebug()
    Logger.setLogWriters(listOf(DebugLogWriter(debug)))
    Logger.setMinSeverity(if (true) Severity.Verbose else Severity.Verbose)
}
Where the internals of the
DebugLogWriter
are as follows:
Copy code
override fun log(severity: Severity, message: String, tag: String, throwable: Throwable?) {
        KermitLogger.log(severity = severity, message = message, tag = tag, throwable = throwable)
    }
Here I have the
DebugLogWriter
simply to override the
isLoggable
, as the
log
calls are simply piped directly back to Kermit