Debugging
The Native SDK provides structured tracing, persistent logging, panic capture, and diagnostic tools for debugging desktop apps.
macOS WebView inspection
For the macOS system WebView backend, Debug app builds enable Safari inspection,
developer extras, and the default Toggle Web Inspector menu item. ReleaseFast,
ReleaseSafe, and ReleaseSmall builds disable them, including the separate release
binary produced by zig build package in an expanded build. This applies to
primary WebViews, secondary windows, and child WebViews, including ones created
later by a native-rendered app.
Override the default with a build option:
Apps that own their build can pass the same option to zig build or
zig build package. Enabling inspection in a release build allows an attached
Safari console to execute JavaScript in the page's origin, including its allowed
native bridge commands. Keep it disabled for normal distribution.
Lower-level hosts initialized directly through AppInfo default to inspection
disabled; set webview_inspection = true explicitly for debugging. This setting
covers WKWebView on macOS and does not configure Chromium or other platforms.
Trace modes
The runtime emits structured trace records. Control verbosity with TraceMode:
| Mode | Description |
|---|---|
off | No trace output |
events | Lifecycle and platform events only (default) |
runtime | Runtime internals: frame timing, invalidation, window state |
all | Everything |
Enable at build time with -Dtrace=true, or parse from a string:
Trace sinks
Trace records are routed through sinks. Native SDK provides three:
FileTraceSink -- appends records to a file on disk:
FanoutTraceSink -- broadcasts to multiple child sinks (e.g. stdout + file):
StdoutTraceSink (from Native SDK's trace module) -- writes to stdout for interactive development.
Wire a sink into the runtime via RuntimeOptions.trace_sink:
Log format
The NATIVE_SDK_LOG_FORMAT environment variable controls the persistent log format:
| Value | Description |
|---|---|
jsonl | JSON Lines -- one JSON object per trace record (default) |
text | Human-readable text lines |
Log paths
Default log file locations by platform:
| Platform | Path |
|---|---|
| macOS | ~/Library/Logs/<bundle-id>/native-sdk.jsonl |
| Linux | ~/.local/state/<bundle-id>/logs/native-sdk.jsonl |
| Windows | %LOCALAPPDATA%<bundle-id>\Logs\native-sdk.jsonl |
Override with NATIVE_SDK_LOG_DIR:
Panic capture
The Native SDK captures Zig panics before the default handler runs:
- Writes a report to
last-panic.txtin the log directory (includes panic message and return address) - Appends a
fataltrace record to the log file - Invokes
std.debug.defaultPanicfor the normal Zig panic output
Enable in your app:
Then call installPanicCapture during startup:
Debug overlay
For apps with web content, build with -Ddebug-overlay=true to enable a visual debugging overlay in the WebView. This shows frame timing, invalidation regions, and window metadata.
See also native doctor for a full diagnostic tool reference.
Environment variables
| Variable | Description |
|---|---|
NATIVE_SDK_LOG_DIR | Override log output directory |
NATIVE_SDK_LOG_FORMAT | Log format: text or jsonl (default: jsonl) |