# Logging and debugging

> Turn on SDK logging on iOS and Android, read the log, preview in-app messages and cards without a server, and confirm what reached Herald.

Turn on debug logging while you integrate, read what the SDK reports, and use the preview hooks to check your message UI without waiting for a real send.

## Log levels

| Level | iOS | Android | What it shows |
|---|---|---|---|
| None | `.none` | `LogLevel.NONE` | Nothing |
| Error | `.error` | `LogLevel.ERROR` | Rejected batches, invalid calls (iOS), disk failures |
| Warning (default) | `.warning` | `LogLevel.WARN` | Plus invalid calls (Android), dropped keys, queue overflow, failed message fetches |
| Info | `.info` | `LogLevel.INFO` | Plus network failures and retry timing, messages that could not show yet |
| Debug | `.debug` | `LogLevel.DEBUG` | Plus accepted batches (Android), events Herald rejected from an accepted batch, unchanged message fetches, discarded messages (Android), card impressions (iOS feed) |

Set the level in the configuration. Use debug in development builds only.

:::tabs
::tab ios
```swift
Herald.configure(appKey: "YOUR_APP_KEY", endpoint: URL(string: "https://YOUR_HERALD_HOST")!) { options in
    #if DEBUG
    options.logLevel = .debug
    #endif
}
```
::tab android
```kotlin
Herald.configure(
    this,
    appKey = "YOUR_APP_KEY",
    endpoint = "https://YOUR_HERALD_HOST",
    options = HeraldOptions(logLevel = if (BuildConfig.DEBUG) LogLevel.DEBUG else LogLevel.WARN),
)
```
:::

## Read the log

:::tabs
::tab ios
The SDK writes to the unified log under subsystem `com.herald.sdk`. Core messages use the category `Herald`; `HeraldUI` uses `ui`. In the Xcode console, filter by the subsystem. From a terminal, with a simulator running:

```sh
xcrun simctl spawn booted log stream --level debug --predicate 'subsystem == "com.herald.sdk"'
```

On a device, use Console.app with the device selected and the same subsystem filter. Turn on **Include Debug Messages** in Console.app's **Action** menu to see debug lines.
::tab android
The SDK writes to Logcat with the tag `Herald`. `herald-ui` and `herald-fcm` use the same tag. In Android Studio, filter by `tag:Herald`. From a terminal:

```sh
adb logcat -s Herald
```
:::

Log lines name calls, statuses and card or message IDs. They do not contain event properties, attribute values or push tokens. On Android, a rejected batch line includes the first 300 characters of the server's error message.

## What to look for

| You see | It means | Next step |
|---|---|---|
| `Herald rejected a batch ...` | Herald returned a 4xx and the batch was dropped | Check the status in [Error codes](/docs/reference/error-codes) |
| `... ignored: ...` | A call broke a rule and was dropped on the device | Fix the call; see [Limits](/docs/reference/limits) |
| `Batch will be retried in N s` (iOS) or `will retry` (Android) | No network or a retryable status | Nothing, unless it repeats for minutes |
| `Event queue full` | More than 1,000 events waited | Find why uploads fail; check for a call in a tight loop |
| `Message sync failed ...` | The fetch failed; cached messages are used | Check the status and the user token |
| `not shown (no presenter or no active scene)` | An in-app message is waiting | Install a presenter after `configure` |
| `Sent N events` (Android, debug) | A batch was accepted | Confirm in Herald |
| `Herald rejected event <id>: <reason> (<detail>)` (debug) | Herald kept the batch but left this event out | Fix the call; see [Rejected events](/docs/reference/error-codes#rejected-events) |
| Nothing at all | `configure` never ran, or the level is too low | Set the level to debug and check `configure` is called |

## Inspect the traffic

To see the exact requests, run the app through an HTTPS debugging proxy you trust and filter for your Herald host. The SDK calls two paths: `POST /api/v1/sdk/batch` and `GET /api/v1/sdk/messages`. Their formats are on [SDK REST endpoints](/docs/reference/rest-endpoints).

To force an upload while you watch, call `flush()`, or send the app to the background.

## Preview messages without a server

Two hooks load and show messages from JSON on the device, so designers and engineers can check every message type and card without an agent send.

:::warning Debug and preview only
`debugLoadMessages` and `debugShowInAppMessage` are public in every build, but they are for debug builds and internal preview screens only. Do not call them in production code paths. Wrap the calls in `#if DEBUG` (iOS) or `if (BuildConfig.DEBUG)` (Android), or keep them in a debug-only source set.
:::

| Hook | What it does |
|---|---|
| `debugLoadMessages(json)` | Replaces the cards and in-app messages in memory with a `GET /api/v1/sdk/messages` response body. Nothing is saved, and the next real fetch replaces them. An unreadable body logs `debugLoadMessages: unreadable body`. |
| `debugShowInAppMessage(messageId)` | Shows a loaded or fetched in-app message now, skipping its trigger, re-eligibility and the minimum interval. Your delegate is still asked on iOS. Does nothing while another message is on screen. |

:::tabs
::tab ios
```swift
#if DEBUG
func previewWelcomeModal() {
    guard let url = Bundle.main.url(forResource: "preview-messages", withExtension: "json"),
          let json = try? Data(contentsOf: url) else { return }
    Herald.shared.debugLoadMessages(json)
    Herald.shared.debugShowInAppMessage("msg_2")
}
#endif
```
::tab android
```kotlin
fun previewWelcomeModal(context: Context) {
    if (!BuildConfig.DEBUG) return
    val json = context.assets.open("preview-messages.json").bufferedReader().use { it.readText() }
    Herald.debugLoadMessages(json)
    Herald.debugShowInAppMessage("msg_2")
}
```
:::

Previewed messages behave like real ones: impressions, clicks and dismissals are queued and sent, and a shown message is recorded in the in-app history. Preview with a test connection and a test user.

## Confirm what reached Herald

1. Send the app to the background or call `flush()`.
2. Confirm the log shows no rejected batch.
3. In Herald, open **Audience > Search users** (admin only) and look up the External ID. The profile shows the attributes and traits written for that user.

Herald has no screen for raw SDK events or devices today. If an event seems missing, check that the user is verified: under **Optional** verification, a batch without a token is stored as anonymous and writes nothing to the profile.

## Related

- [Troubleshooting](/docs/operations/troubleshooting)
- [Error codes](/docs/reference/error-codes)
- [Data batching and offline behavior](/docs/concepts/batching-and-offline)
