Multiplatform logging and analytics tool written in Kotlin.
Kimchi is published to Maven Central with the following maven
coordinates:
com.inkapplications.kimchi:core
You can find the latest version info on GitHub
To use the logger, just add a log writer to determine where to write logs to:
fun main() {
// Add one or more log writers:
Kimchi.addLog(defaultWriter)
// Send Logs:
Kimchi.info("Hello World")
}
defaultWriter
will select the most applicable default
for the current platform.
StandardWriter
will print logs to the standard
output console for the platform.
AdbWriter
will print logs to
ADB.
ConsoleWriter
will print logs
to the javascript console object.
You can add as many log writers as you'd like.
Use these built-in writers, or write your own by extending
LogWriter
You can easily filter out logs of a certain level by
using withThreshold
:
fun main() {
Kimchi.add(defaultWriter.withThreshold(LogLevel.INFO))
// Logs lower than the threshold will not show up:
Kimchi.trace("This log is filtered")
Kimchi.info("This log still shows!")
}
If generating a log string is expensive, you can lazily generate the log string with a lambda, which will not be invoked if the log is disabled:
fun main() {
Kimchi.addLog(defaultWriter.withThreshold(LogLevel.INFO))
Kimchi.debug { "Getting this log could be expensive: ${getExpensiveInfo()}" }
}
Analytics is set up very similar to logging. To start using analytics, you'll need to add a writer, just like logging:
fun main() {
// Add one or more analytics writers:
Kimchi.addAnalytics(KimchiLoggerAnalytics) // send analytics events to the logger.
// Send Analytics Events:
Kimchi.trackEvent("Hello Analytics!")
}
Just like logging, you can implement the AnalyticsWriter
interface to add any analytics platform your app is using.
Most analytics platforms allow you to set application-wide properties. These can be used to describe the application state or user info that persists across multiple events.
fun main() {
Kimchi.setProperty(intProperty("age", 25))
}
Properties can be created for any of the following primitive types:
stringProperty
intProperty
floatProperty
doubleProperty
longProperty
Properties can also be included in events and screen tracking:
fun example() {
Kimchi.trackEvent(
name = "Purchase Complete",
properties = listOf(
intProperty("Items", 5),
stringProperty("State", "CA")
)
)
}
Kimchi has adapters to automatically log analytics events to Firebase Analytics, and non-fatal logs to Firebase Crashlytics.