Logging and Debugging (Version 3.x)

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 Data 360 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.

There are two equivalent ways to access the Data 360 Module after initialization:

  • SFMCSdk.cdp — access via the unified SFMCSDK namespace (preferred for consistency with other modules)
  • CdpModule.shared (iOS) / CdpSdk.requestSdk (Android) — direct singleton access

Both refer to the same module instance.

// Inspect full SDK state as a JSON string
print(CdpModule.shared.state)

// Or via the unified SDK accessor
print(SFMCSdk.cdp.state)
CdpSdk.requestSdk { sdk ->
    val state = sdk.state
    Log.d("MyApp", sdk.state.toString(2))
}

Always inspect the SDK state during debugging to verify your configuration and understand the SDK's current status.

iOS State Output Example

{
  "name": "cdp",
  "version": "3.0.1",
  "User-Agent": "CDP-iOS/3.0.1 ...",
  "config": {
    "appId": "your-app-source-id",
    "endpoint": "https://your-endpoint.salesforce.com/",
    "sessionTimeout": 600,
    "trackLifecycle": false,
    "trackScreens": false
  },
  "consentManager": {
    "consent": "optIn",
    "deviceId": "A1B2C3D4-...",
    "partyIdentificationUserId": ""
  },
  "sessionManager": {
    "sessionId": "E5F6G7H8-..."
  },
  "eventManager": {
    "queueSize": 0
  },
  "locationManager": {
    "latitude": 37.7749,
    "longitude": -122.4194,
    "expiration": 1712345678
  }
}
  • locationManager is an empty object {} when no location is set or it has expired.
  • consentManager.partyIdentificationUserId is populated when the SFMCSDK push module has set a subscriber key.
  • When the tenant has been deprovisioned (server returned 401 with APP_SOURCE_UNKNOWN), the entire state string is "Deprovisioned" (not JSON).
  • expiration in locationManager is a Unix timestamp (seconds since epoch).

Android State Output Example

{
  "name": "CDP",
  "moduleState": "READY",
  "config": {
    "appId": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "endpoint": "https://your-endpoint.salesforce.com",
    "sessionTimeout": 600,
    "trackLifecycle": false,
    "trackScreens": false
  },
  "consentManager": {
    "consent": "OPT_IN",
    "deviceId": "xxxxxxxx"
  },
  "sessionManager": {
    "sessionId": "xxxxxxxx"
  },
  "eventManager": {
    "queueSize": 3
  },
  "locationManager": {
    "latitude": 37.7749,
    "longitude": -122.4194,
    "expiration": 1234567890
  }
}
  • locationManager fields are omitted when no location is set.
  • moduleState values are INITIALIZING, READY, and TENANT_DEPROVISIONED.