Logging and Debugging
Logging is optional, yet critical, SDK feature that allows the mobile application
developer to select the verbosity of the Data Cloud Module for the Engagement Mobile SDK’s
output. By default, logging is disabled and must be enabled using the
setLogger for iOS or setLogging for Android method on
the SFMCSdk instance. Define the desired logging level and output destination. Enabling logging
results in log capture using the native unified logging system.
Log Levels
| Log Level | Description |
|---|---|
| Error | This log level provides details about unrecoverable errors associated with inability to complete valuable business use cases. |
| Warn | This log level indicates the SDK integration has a problem or it encountered an unusual situation. Warnings are associated with potentially harmful, but recoverable errors. |
| Debug | This log level provides granular, low-level information about how the SDK processes tasks, events, and error details. Debug logging enables developers to perform diagnostics on their application to troubleshoot issues. |
Logging Example
iOS
Android
1import SFMCSDK
2
3...
4
5// set the logger to show debug messages and higher
6SFMCSdk.setLogger(LogLevel.debug)
7
8// example usage
9let CATEGORY = LoggerCategory.module
10
11SFMCSdkLogger.shared.d(category: CATEGORY, message: "Logs a debug message.")
12
13SFMCSdkLogger.shared.w(category: CATEGORY, message: "Logs a warning message.")
14
15SFMCSdkLogger.shared.e(category: CATEGORY, message: "Logs an error message.")1import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk
2import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel
3import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener.AndroidLogger
4
5...
6
7// set the logger to show debug messages and higher
8SFMCSdk.setLogging(LogLevel.DEBUG, AndroidLogger())
9
10// example usage
11val TAG = "Example Application"
12val ERROR = IllegalStateException("Example Failure")
13
14SFMCSdkLogger.d(TAG) { "Logs a debug message." }
15SFMCSdkLogger.d(TAG, ERROR) { "Logs a debug message along with the error." }
16
17SFMCSdkLogger.w(TAG) { "Logs a warning message." }
18SFMCSdkLogger.w(TAG, ERROR) { "Logs a warning message along with the error." }
19
20SFMCSdkLogger.e(TAG) { "Logs an error message." }
21SFMCSdkLogger.e(TAG, ERROR) { "Logs an error message along with the error." }SDK State Example
The state property on the Data Cloud Module returns operational information containing current configuration settings, session details, event queue size, and consent state. This information is critical for debugging and troubleshooting purposes.
iOS1SFMCSdk.state()1SFMCSdk.requestSdk { sdk -> sdk.getSdkState() }SDK State is a tool to assist development and troubleshooting. Always inspect the SDK state when debugging to confirm expected configuration.
Example Engagement Mobile SDK State:
1{
2 "modules": {
3 "cdp": {
4 "compatibility": "1.9.0 - 2.9.9",
5 "name": "cdp",
6 "pendingOperations": "0",
7 "properties": {
8 "appId": "YOUR_APP_ID
9",
10 "consent": "opt_in",
11 "endpoint": "YOUR_ENDPOINT",
12 "version": "2.0.1"
13 },
14 "status": "operational",
15 "version": "2.0.1"
16 },
17 "push": {
18 "compatibility": "8.0.3 - 8.9.9",
19 "name": "push",
20 "pendingOperations": "undefined",
21 "status": "inactive",
22 "version": "unavailable"
23 }
24 },
25 "registrationId": "YOUR_APPLICATION_REGISTRATION_ID",
26 "version": "1.0.2"
27}