Skip to main content

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:

Setting the log level (Swift)
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:

Setting the log level (Kotlin)
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:

1. Connect Your Device or Use Simulator

Ensure your app is installed and running on a simulator or a real device connected via USB.

2. Open the Devices and Simulators Window

  • Launch Xcode.
  • Go to Window > Devices and Simulators (or press Cmd + Shift + 2).

3. Select Your Device

  • In the Devices tab, select the connected device or simulator running your app.

4. Locate the App Container

Under the Installed Apps section:

  • Find your app in the list.
  • Click the gear icon next to it.
  • Choose Download Container…

5. Save the App Container

  • Save the .xcappdata file to a local folder.
  • Once saved, right-click it and choose Show Package Contents.

6. Navigate to logs_mPower

Within the extracted container:

AppData/Document/logs_mPower/

This folder contains your log files. You can now copy or archive them as needed.


Sample Swift Code to Print Log File Paths

You can use the following code snippet to print the absolute paths of the logs:

let fileManager = FileManager.default
if let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first {
let logsFolderURL = documentsURL.appendingPathComponent("logs_mPower")
do {
let logFiles = try fileManager.contentsOfDirectory(at: logsFolderURL, includingPropertiesForKeys: nil)
logFiles.forEach { print("Log file path: \($0.path)") }
} catch {
print("Error accessing logs: \(error)")
}
}

Summary

Exporting logs from the logs_mPower directory is straightforward with Xcode:

  1. Open Devices and Simulators.
  2. Download the app container.
  3. Extract and browse to Documents/logs_mPower/.

Android/Kotlin

On Android the SDK will try to export the logs to your app's externalFilesDir, from there they can be easily retrieved through any file explorer (for example the Device Explorer in Android Studio). If externalFilesDir is not writable for some reason the SDK will try to write the logs to your app's filesDir and finally to the cacheDir. The logs will always be in a folder called logs_mPower. If you want to add some logic in your app to copy/export the logs or share them via e-mail be sure to check the following paths for a folder called logs_mPower in the giving order: getExternalFilesDir() > getFilesDir() > getCacheDir().

Where Are Logs Stored?

In Android, getExternalFilesDir() returns a directory specific to your app on the external storage.

Typical path:

/storage/emulated/0/Android/data/<your.package.name>/files/logs_mPower/

This location is:

  • Private to the app (not visible to other apps)
  • Persistent across app restarts
  • Deleted when the app is uninstalled

Exporting Logs

Option 1: Using Android Studio (Device Explorer)

  1. Run your app on a connected device or emulator.

  2. Open Android Studio.

  3. Go to View > Tool Windows > Device Explorer.

  4. In the left panel:

    • Expand data > data > <your.package.name> > files
    • Locate the logs_mPower/ folder
  5. Right-click the folder or filesSave As to export them to your local machine.


Option 2: Using ADB (Android Debug Bridge)

1. Connect your device via USB and verify it's connected:

adb devices

2. Pull the log folder from the device:

adb pull /sdcard/Android/data/<your.package.name>/files/logs_mPower ./logs_export/

This copies the logs from the device to your local machine in the ./logs_export folder.

On some devices, you may need to use /storage/emulated/0/ instead of /sdcard/.

Permissions

If targeting Android 10 (API 29) or higher:

  • You do not need WRITE_EXTERNAL_STORAGE permission for getExternalFilesDir().
  • The directory remains app-private.

For older targets:

  • You may need to request android.permission.WRITE_EXTERNAL_STORAGE.

Summary

ToolWhat to Do
Android StudioUse Device Explorer to browse and download files
ADBUse adb pull to extract logs from getExternalFilesDir