TomTomSDK Logging configuration
This tutorial explains how to enable and configure logging for the Android SDK modules. Logs are intended for issue analysis and can be enabled for debugging purposes. By default, logging is disabled.
Enabling logging may have a minor performance impact depending on the LogLevel, a lower LogLevel would result in higher number of logs and causing a greater impact on performance. Thus it is recommended to only enable it during development and debugging. For production builds, it should be disabled.
Project setup
Configure the project as described in the Project setup guide. Then add the following dependencies to the build.gradle.kts file of your application module and synchronize the project.
implementation("com.tomtom.sdk:init:2.4.2")Configure Logging
Logging can be configured as a part of the SDK initialization, through TomTomSdk object
TomTomSdk.initialize( context = application, sdkConfiguration = buildSdkConfiguration( context = application, apiKey = TOMTOM_API_KEY, coreConfiguration = { // Configure logging here. loggingConfiguration = { level = LogLevel.INFO sink = MyCustomLogSink } }, ),)There are two configuration options:
- A minimum
LogLevelto output only logs that start from that log level and above. The default value is set toLogLevel.NONE, which means that no logs are output. - A
LogSinkinstance to route log output to a destination and for additional log filtering. The default is set toAndroidLogSinkclass, that routes log output toAndroid Logcat. Users can also define their own customLogSinkimplementation for their specific use case (e.g.: Logging to a file).
Custom log sink implementation
The following is an example LogSink implementation which routes log output to the Android logging framework.
class MyCustomLogSink : LogSink { override fun i( tag: String, message: String, throwable: Throwable?, ) { Log.i(tag, message, throwable) }
override fun w( tag: String, message: String, throwable: Throwable?, ) { Log.w(tag, message, throwable) }
override fun e( tag: String, message: String, throwable: Throwable?, ) { Log.e(tag, message, throwable) }
override fun wtf( tag: String, message: String, throwable: Throwable?, ) { Log.wtf(tag, message, throwable) }}