> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spendowl.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Debugging

> Logging and troubleshooting the SpendOwl SDK

## Enable Logging

Turn on debug logging to see SpendOwl activity:

```swift theme={null}
SpendOwl.enableLogging = true
```

<Warning>
  Disable logging in production builds. Logs may contain sensitive information.
</Warning>

### Using Build Flags

Enable logging only in debug builds:

```swift theme={null}
#if DEBUG
SpendOwl.enableLogging = true
#endif
```

## Log Levels

For more control, use `logLevel`:

```swift theme={null}
SpendOwl.logLevel = .debug
```

| Level    | Description                       |
| -------- | --------------------------------- |
| `.none`  | No logging (default)              |
| `.error` | Only errors                       |
| `.info`  | Errors and important events       |
| `.debug` | All messages including debug info |

### Example Output

```
[SpendOwl] SpendOwl SDK v1.0.0 configured
[SpendOwl] Fetching attribution token...
[SpendOwl] Attribution token received: eyJ0...
[SpendOwl] Sending attribution to server...
[SpendOwl] Attribution result: attributed (Campaign: Winter Sale)
[SpendOwl] Purchase tracking started
[SpendOwl] User ID set: user-123...
[SpendOwl] Purchase tracked: com.app.premium ($9.99 USD)
```

## Console.app Integration

SpendOwl logs are written to the system log using `os_log`. To view them:

<Steps>
  <Step title="Open Console.app">
    Find Console in `/Applications/Utilities/Console.app`
  </Step>

  <Step title="Select Your Device">
    Choose your device or simulator from the sidebar
  </Step>

  <Step title="Filter by SpendOwl">
    In the search bar, type `SpendOwl` to filter logs
  </Step>
</Steps>

<Tip>
  Console.app shows logs even when Xcode isn't running—useful for testing on physical devices.
</Tip>

## Common Issues

### SDK Not Configured

```
Error: SpendOwl SDK is not configured
```

**Solution:** Call `configure()` before using other SDK methods:

```swift theme={null}
// In App.init() or AppDelegate
SpendOwl.configure(apiKey: "your-api-key")
```

### Invalid API Key

```
Error: Invalid API key
```

**Solution:** Check your API key in the [dashboard](https://spendowl.io/dashboard). Ensure you're using the correct key for your environment (test vs. live).

### Network Errors

```
Error: Network error: The request timed out
```

**Solutions:**

* Check internet connectivity
* Increase timeout: `SpendOwlConfiguration(apiKey: "...", timeoutInterval: 30)`
* The SDK retries automatically, but persistent failures indicate network issues

### Attribution Unavailable

```
Error: Attribution is not available on this device
```

**Causes:**

* iOS version below 14.3
* AdServices framework not available
* Running in simulator (attribution may return mock data)

**Solution:** Attribution works on iOS 14.3+ on real devices. Simulators may return limited data.

### Attribution Denied

```
Error: Attribution access was denied
```

**Causes:**

* User or MDM restricted ad tracking
* Limited Ad Tracking enabled in Settings

**Solution:** This is normal for some users. Handle gracefully:

```swift theme={null}
do {
    let attribution = try await SpendOwl.attribution()
} catch SpendOwlError.attributionDenied {
    // User has restricted tracking - continue without attribution
}
```

## Verifying Integration

Use this checklist to verify SpendOwl is working:

<Steps>
  <Step title="Check Configuration">
    ```swift theme={null}
    print(SpendOwl.isConfigured) // Should be true
    ```
  </Step>

  <Step title="Check SDK Version">
    ```swift theme={null}
    print(SpendOwl.sdkVersion) // Should print "1.0.0"
    ```
  </Step>

  <Step title="Enable Logging">
    ```swift theme={null}
    SpendOwl.enableLogging = true
    ```
  </Step>

  <Step title="Trigger Attribution">
    ```swift theme={null}
    let attribution = try await SpendOwl.attribution()
    print(attribution.status) // Should print a status
    ```
  </Step>

  <Step title="Check Dashboard">
    Visit your [SpendOwl Dashboard](https://spendowl.io/dashboard) to see if events appear
  </Step>
</Steps>

## Debug Mode in Dashboard

The SpendOwl dashboard shows debug data when using a test API key:

* Test events are labeled separately
* Don't affect production ROAS
* Useful for verifying integration

## Reporting Issues

If you encounter issues not covered here:

1. Enable `.debug` logging
2. Reproduce the issue
3. Copy the logs
4. Open an issue on [GitHub](https://github.com/spendowl/spendowl-ios/issues)

Include:

* iOS version
* SDK version
* Relevant logs
* Steps to reproduce

## Next Steps

<CardGroup cols={2}>
  <Card title="Troubleshooting" icon="wrench" href="/resources/troubleshooting">
    Common issues and solutions
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/spendowl">
    Full SDK API documentation
  </Card>
</CardGroup>
