Debugging
zero-native provides structured tracing, persistent logging, panic capture, and diagnostic tools for debugging desktop apps.
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:
const mode = zero_native.debug.parseTraceMode("all"); // returns ?TraceModeTrace sinks
Trace records are routed through sinks. zero-native provides three:
FileTraceSink -- appends records to a file on disk:
var file_sink = zero_native.debug.FileTraceSink.init(io, log_dir, log_file, .json_lines);FanoutTraceSink -- broadcasts to multiple child sinks (e.g. stdout + file):
var sinks = [_]trace.Sink{ stdout_sink.sink(), file_sink.sink() };
var fanout = zero_native.debug.FanoutTraceSink{ .sinks = &sinks };StdoutTraceSink (from zero-native's trace module) -- writes to stdout for interactive development.
Wire a sink into the runtime via RuntimeOptions.trace_sink:
var runtime = zero_native.Runtime.init(.{
.platform = my_platform,
.trace_sink = fanout.sink(),
});Log format
The ZERO_NATIVE_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>/zero-native.jsonl |
| Linux | ~/.local/state/<bundle-id>/logs/zero-native.jsonl |
| Windows | %LOCALAPPDATA%<bundle-id>\Logs\zero-native.jsonl |
Override with ZERO_NATIVE_LOG_DIR:
ZERO_NATIVE_LOG_DIR=/tmp/my-logs zig build run-webviewPanic capture
zero-native 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:
pub const panic = std.debug.FullPanic(zero_native.debug.capturePanic);Then call installPanicCapture during startup:
zero_native.debug.installPanicCapture(io, log_setup.paths);Debug overlay
Build with -Ddebug-overlay=true to enable a visual debugging overlay in the WebView. This shows frame timing, invalidation regions, and window metadata.
zig build run-webview -Ddebug-overlay=trueSee also zero-native doctor for a full diagnostic tool reference.
Environment variables
| Variable | Description |
|---|---|
ZERO_NATIVE_LOG_DIR | Override log output directory |
ZERO_NATIVE_LOG_FORMAT | Log format: text or jsonl (default: jsonl) |