Logging is an important SDK feature that lets you control the verbosity of the SDK's output. By default, logging is disabled. You must enable it by defining a log level and output destination using the setLogger method for iOS or setLogging method for Android on the SFMCSdk instance. Once enabled, the SDK uses the native unified logging system to capture log output.
Log Levels
| Log Level | Description |
|---|---|
Error |
Details unrecoverable errors that prevent key functionalities from working. |
Warn |
Highlights potential problems or unexpected situations. These are typically recoverable issues that won't stop the SDK from functioning but should be addressed. |
Debug |
Provides detailed, low-level information about the SDK's internal operations. Use this level for in-depth troubleshooting and diagnostics. |
Logging Example
Here's how you can enable and use logging in your application.
import SFMCSDK
...
// Set the logger to show debug messages and higher
SFMCSdk.setLogger(logLevel: .debug)
// Example usage
let CATEGORY = LoggerCategory.module
SFMCSdk.logger.d(category: CATEGORY, message: "Logs a debug message.")
SFMCSdk.logger.w(category: CATEGORY, message: "Logs a warning message.")
SFMCSdk.logger.e(category: CATEGORY, message: "Logs an error message.")
import com.salesforce.marketingcloud.sfmcsdk.SFMCSdk
import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogLevel
import com.salesforce.marketingcloud.sfmcsdk.components.logging.LogListener.AndroidLogger
...
// Set the logger to show debug messages and higher
SFMCSdk.setLogging(LogLevel.DEBUG, AndroidLogger())
// Example usage
val TAG = "Example Application"
val ERROR = IllegalStateException("Example Failure")
SFMCSdk.logger.d(TAG) { "Logs a debug message." }
SFMCSdk.logger.d(TAG, ERROR) { "Logs a debug message along with the error." }
SFMCSdk.logger.w(TAG) { "Logs a warning message." }
SFMCSdk.logger.w(TAG, ERROR) { "Logs a warning message along with the error." }
SFMCSdk.logger.e(TAG) { "Logs an error message." }
SFMCSdk.logger.e(TAG, ERROR) { "Logs an error message along with the error." }
SDK State Example
The state property of the SDK returns operational information containing current configuration settings, session details, event queue size, and consent state. This information is critical for debugging and troubleshooting purposes.
SFMCSdk.state()
SFMCSdk.requestSdk { sdk -> sdk.getSdkState() }
Always inspect the SDK state during debugging to verify your configuration and understand the SDK's current status.
Here's an example of the SDK state output:
{
"modules": {
"cdp": {
"compatibility": "1.9.0 - 2.9.9",
"name": "cdp",
"pendingOperations": "0",
"properties": {
"appId": "YOUR_APP_ID",
"consent": "opt_in",
"endpoint": "YOUR_ENDPOINT",
"version": "2.0.1"
},
"status": "operational",
"version": "2.0.1"
},
"push": {
"compatibility": "8.0.3 - 8.9.9",
"name": "push",
"pendingOperations": "undefined",
"status": "inactive",
"version": "unavailable"
}
},
"registrationId": "YOUR_APPLICATION_REGISTRATION_ID",
"version": "1.0.2"
}