---
schema_version: "1"
id: 5f0f615a831f189bbe077c5c22652412441aba5bf479694e1e354be9da0e049c
title: Logging and Debugging (Version 2.x)
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/data-cloud/data-cloud-engagement-mobile-sdk/guides/c360a-api-engagement-mobile-sdk-logging-and-debugging-v2.md
canonical_url: https://developer.salesforce.com/docs/data/data-cloud-engagement-mobile-sdk/guide/c360a-api-engagement-mobile-sdk-logging-and-debugging-v2.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: 6398942706ed5d4f0818bcb4c50f1d3677fcc4f18d0daa66d2d49a3c130e7740
products:
  - Data 360 Engagement Mobile SDK
  - Data 360 Developer Documentation
---
# Logging and Debugging (Version 2.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 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:

```json
{
  "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"
}
```
