Skip to the content.
Overview Store View Binding and Lifecycle State preservation Logging Time travel

Logging

Logging is an essential tool for almost every app. MVIKotlin provides logging functionality via the LoggingStoreFactory wrapper located in the mvikotlin-logging module. It is possible to replace the default Logger and LogFormatter with a custom ones.

⚠️ Logging is a debugging tool and may affect performance, ideally it should not be used in production.

Using LoggingStoreFactory

Suppose we have the following Store factory:

internal class CalculatorStoreFactory(private val storeFactory: StoreFactory) {

    fun create(): CalculatorStore =
        object : CalculatorStore, Store<Intent, State, Nothing> by storeFactory.create(
            name = "CounterStore",
            // ...
        ) {
        }

    // ...
}

It accepts a StoreFactory and uses it to create an implementation of the CalculatorStore. You can now pass any StoreFactory here. So if you want to add logging just pass an instance of the LoggingStoreFactory:

val storeFactory = LoggingStoreFactory(DefaultStoreFactory)

CalculatorStoreFactory(storeFactory).create()

Normally you should define a global StoreFactory somewhere in the main app and pass it down to all the dependencies.

Please refer to the samples for more examples.

Overview Store View Binding and Lifecycle State preservation Logging Time travel