Logging
Setting the Log Level
SDK Logging is started automatically when the MasterController is initialized. The default log level is KSMLogInfo
or INFO
. To get a more detailed log during debugging, it can sometimes be helpful to switch it to KSMLogTrace
or TRACE
, but this is way to verbose to use it by default. Also note that the choice of log level can have an influence on timing, so if you are e.g. investigating a bug related to a race condition, it is possible that the problem will not occur when switching to a different log level.
⚠️ IMPORTANT: Do NOT use TRACE log level in production/release applications! Otherwise you risk confidential data being written to disk. Even though the logs are encrypted we strongly advice against using TRACE level outside of testing/debugging!
We suggest to not use the log levels that are less verbose than INFO
as those do give only information on errors when they actually happen, but in practice it turns out that they almost never provide sufficient context to diagnose the reason for an error.
iOS/Swift
Under iOS, choosing a different log level may look as follows:
var logSink: KSMLogSink?
func setLogLevel(logLevel: KSMLogLevel) {
if logSink == nil {
logSink = KSMasterControllerFactory.getLogSink()
}
logSink?.setSeverityLevel(logLevel)
}
Android/Kotlin
For Android, we suggest setting the log level in the onCreate of your Application Class, as shown in this code snippet:
import com.kobil.wrapper.logger.Log
...
...
override fun onCreate() {
super.onCreate()
Log.setSeverity(Severity.TRACE)
}
Exporting Logs
The logs are written to the app's DocumentsDirectory on iOS, while on Android the app's cache dir (for example /data/data/com.kobil.mcwmpgettingstarted/cache/logs_mPower/) is used. Those directories are not accessible in release builds (at least not easily) so you will want to export the logs to an accessible dir.
iOS/Swift
Exporting Log Files from logs_mPower
in iOS Using Xcode
When debugging or gathering analytics, it can be useful to access log files generated by MCSDK in your iOS app. MCSDK writes logs to a specific folder in the Documents directory—such as logs_mPower
—you can easily extract those logs using Xcode tools.
This guide explains how to locate and export the logs_mPower
folder from the iOS Documents directory using Xcode.
Where Are Logs Stored?
On iOS, files saved in the app's Documents directory are sandboxed per app, but accessible when the app is run on a simulator or connected device in development mode.
In this case, your app saves logs to:
<app sandbox>/Documents/logs_mPower/
How to Export Logs Using Xcode
Follow these steps to export the log files using Xcode: