Kotlin logger integration
In this doc we will learn how we can integrate our code with Nativeblocks
Get started
Make sure that your project meets these requirements:
- Uses Android API level 26 or higher
- Uses Jetpack (AndroidX)
Initialization
Root gradle
repositories {
mavenCentral()
}
Module gradle
dependencies {
implementation ("io.nativeblocks:nativeblocks-android:1.0.1")
}
After initialization we need to write our analytic logger and then import it into Nativeblocks
In this doc we will cover basic SDK api
Event manager
Let's start to build our analytic logger,
We have one function to send logs to a third-party analytic system,
fun eventManager(
eventName: String,
parameters: Map<String, String>
) {
firebaseAnalytics.logEvent(eventName, parameters.toBundle())
...
}
Event manager into logger
After providing all properties we have to wrap it into Nativeblocks SDK,
class FirebaseAnalytics : INativeLogger {
override fun log(eventName: String, parameters: Map<String, String>) {
eventManager(eventName, parameters)
}
}
Register logger
At the end the FirebaseAnalytics must be registered into Nativeblocks,
NativeblocksManager.getInstance().provideEventLogger(
loggerType = "FIREBASE_ANALYTICS_LOGGER",
logger = FirebaseAnalytics()
)
From now on, every action that happens in Nativeblocks will be reported to the FIREBASE_ANALYTICS_LOGGER
Debug logger
Additionally, we can use a logger interface to integrate our debugging logs
class DebugLogger : INativeLogger {
override fun log(eventName: String, parameters: Map<String, String>) {
Log.d("MY_AWESOME_APP", "$eventName: $parameters")
}
}
Finally we need to register our logger to Nativeblocks
NativeblocksManager.getInstance().provideEventLogger(
loggerType = "DEBUG_LOGGER",
logger = DebugLogger()
)
Now we have full observability of all events that happen in Nativeblocks