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.
Legal Restrictions.
If you enable logging, you as the customer would be responsible for the management of the logs and ensuring compliance with data protection regulations, as logs may contain personally identifiable information (PII) or other sensitive data.
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.1")
Configure Logging
Logging can be configured as a part of the SDK initialization, through TomTomSdk object
1TomTomSdk.initialize(2 context = application,3 sdkConfiguration = buildSdkConfiguration(4 context = application,5 apiKey = TOMTOM_API_KEY,6 coreConfiguration = {7 // Configure logging here.8 loggingConfiguration = {9 level = LogLevel.INFO10 sink = MyCustomLogSink11 }12 },13 ),14)
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.
1class MyCustomLogSink : LogSink {2 override fun i(3 tag: String,4 message: String,5 throwable: Throwable?,6 ) {7 Log.i(tag, message, throwable)8 }910 override fun w(11 tag: String,12 message: String,13 throwable: Throwable?,14 ) {15 Log.w(tag, message, throwable)16 }1718 override fun e(19 tag: String,20 message: String,21 throwable: Throwable?,22 ) {23 Log.e(tag, message, throwable)24 }2526 override fun wtf(27 tag: String,28 message: String,29 throwable: Throwable?,30 ) {31 Log.wtf(tag, message, throwable)32 }33}