|
| 1 | +--- |
| 2 | +title: Structured File Logs |
| 3 | +description: Persist Zephyr build output as structured files for easier debugging, CI archiving, and log ingestion. |
| 4 | +head: |
| 5 | + - - meta |
| 6 | + - property: og:description |
| 7 | + content: Persist Zephyr build output as structured files for easier debugging, CI archiving, and log ingestion. |
| 8 | +--- |
| 9 | + |
| 10 | +# Structured File Logs |
| 11 | + |
| 12 | +Zephyr build integrations now support structured, file-based logging for every build run. When enabled, logs are written to disk in addition to the terminal, making it easier to debug build issues locally and to store artifacts from CI. |
| 13 | + |
| 14 | +## Quick start |
| 15 | + |
| 16 | +- Enable logging for a single command: |
| 17 | + |
| 18 | +```bash |
| 19 | +ZEPHYR_LOG_TO_FILE=true pnpm build |
| 20 | +``` |
| 21 | + |
| 22 | +- Choose TOON encoding instead of JSON: |
| 23 | + |
| 24 | +```bash |
| 25 | +ZEPHYR_LOG_TO_FILE=true ZEPHYR_LOG_FORMAT=toon pnpm build |
| 26 | +``` |
| 27 | + |
| 28 | +- Override the default log directory: |
| 29 | + |
| 30 | +```bash |
| 31 | +ZEPHYR_LOG_TO_FILE=true ZEPHYR_LOG_PATH=/tmp/zephyr-logs pnpm build |
| 32 | +``` |
| 33 | + |
| 34 | +## Where logs are stored |
| 35 | + |
| 36 | +- **Default path:** `~/.zephyr/logs/` (override with `ZEPHYR_LOG_PATH`) |
| 37 | +- **Per-run folders:** Each command creates `run-<timestamp>/` so logs from different runs never collide |
| 38 | +- **File naming:** Logs are split by intent to keep them targeted: |
| 39 | + - `info.log`, `warn.log`, `error.log` |
| 40 | + - `action-<action>.log` (actions use the Zephyr log action names; colons become hyphens) |
| 41 | + - `debug-<context>.log` for `zephyr:*` debug namespaces (captured even if `DEBUG` is not set) |
| 42 | +- **Summary:** When the CLI writes run metadata, it is saved to `summary.json` with timestamps, duration, build ID, and any reported counts. |
| 43 | + |
| 44 | +### Example layout |
| 45 | + |
| 46 | +``` |
| 47 | +~/.zephyr/logs/run-2024-06-14T18-22-05/ |
| 48 | + info.log |
| 49 | + warn.log |
| 50 | + error.log |
| 51 | + action-build.log |
| 52 | + debug-git.log |
| 53 | + summary.json |
| 54 | +``` |
| 55 | + |
| 56 | +## Log formats |
| 57 | + |
| 58 | +- **JSON (default):** One JSON object per line with `level`, `message`, `timestamp`, `action`, and any structured payloads. |
| 59 | +- **TOON:** Set `ZEPHYR_LOG_FORMAT=toon` to emit [TOON](https://www.npmjs.com/package/@toon-format/toon) encoded entries for downstream tooling that prefers the format. |
| 60 | + |
| 61 | +## Structured payload extraction |
| 62 | + |
| 63 | +- When a log line contains valid JSON (for example, API responses), the builder separates the text from the parsed payload: |
| 64 | + - `message` keeps the human-readable text |
| 65 | + - `payload` contains the parsed JSON object or array |
| 66 | +- ANSI color codes are stripped before writing, so files stay clean for parsers and artifact viewers. |
| 67 | + |
| 68 | +## CI recommendations |
| 69 | + |
| 70 | +- Turn on file logging for build steps where you already capture artifacts: `ZEPHYR_LOG_TO_FILE=1` |
| 71 | +- Set `ZEPHYR_LOG_PATH` to a workspace-relative folder (e.g., `./artifacts/zephyr-logs`) so your pipeline can zip and upload it |
| 72 | +- Keep `DEBUG` off if you do not want verbose console output—debug namespaced logs are still captured on disk when file logging is enabled |
| 73 | + |
| 74 | +With file logging enabled, every Zephyr build run produces durable, structured logs you can inspect locally, attach to bug reports, or feed into your log processing pipeline. |
0 commit comments