Capture Behavior Data
Version 3.x
Version 2.x
Post Data from an Authenticated Server-to-Server Connection
Post Data from an Unauthenticated Server-to-Server Connection
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 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. |
Here’s how you can enable and use logging in your application.
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
11SFMCSdk.logger.d(category: CATEGORY, message: "Logs a debug message.")
12SFMCSdk.logger.w(category: CATEGORY, message: "Logs a warning message.")
13SFMCSdk.logger.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
14SFMCSdk.logger.d(TAG) { "Logs a debug message." }
15SFMCSdk.logger.d(TAG, ERROR) { "Logs a debug message along with the error." }
16
17SFMCSdk.logger.w(TAG) { "Logs a warning message." }
18SFMCSdk.logger.w(TAG, ERROR) { "Logs a warning message along with the error." }
19
20SFMCSdk.logger.e(TAG) { "Logs an error message." }
21SFMCSdk.logger.e(TAG, ERROR) { "Logs an error message along with the error." }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.
1SFMCSdk.state()1SFMCSdk.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:
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 "consent": "opt_in",
10 "endpoint": "YOUR_ENDPOINT",
11 "version": "2.0.1"
12 },
13 "status": "operational",
14 "version": "2.0.1"
15 },
16 "push": {
17 "compatibility": "8.0.3 - 8.9.9",
18 "name": "push",
19 "pendingOperations": "undefined",
20 "status": "inactive",
21 "version": "unavailable"
22 }
23 },
24 "registrationId": "YOUR_APPLICATION_REGISTRATION_ID",
25 "version": "1.0.2"
26}