Kimchi

Multiplatform logging and analytics tool written in Kotlin.

Installation

If you haven’t already, add JitPack to your gradle repositories in your build.gradle file:


repositories {
    maven { url "https://jitpack.io" }
}

Next, add the main Kimchi dependency:


compile "com.github.Inkapplications.kimchi:kimchi:+" // Replace with exact version

Logging

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")
}

You can add as many log writers as you'd like. Use these built-in writers, or write your own by extending LogWriter

Filter Logs

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!")
}

Lazy Logs

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

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.

Properties

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:

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")
        )
    )
}

Logging & Analytics Integrations

Firebase (Android)

Kimchi has adapters to automatically log analytics events to Firebase Analytics, and non-fatal logs to Firebase Crashlytics.

View Project