refactor(logging): add subsystem console formatting

This commit is contained in:
Peter Steinberger
2025-12-21 13:23:42 +00:00
parent bcd3c13e2c
commit 5b2e7d4464
6 changed files with 303 additions and 2 deletions

View File

@@ -46,10 +46,18 @@ If set, CLAWDIS derives defaults (only when you havent set them explicitly):
- Default log file: `/tmp/clawdis/clawdis-YYYY-MM-DD.log`
- If you want a stable path, set `logging.file` to `/tmp/clawdis/clawdis.log`.
- Console output can be tuned separately via:
- `logging.consoleLevel` (defaults to `info`, bumps to `debug` when `--verbose`)
- `logging.consoleStyle` (`pretty` | `compact` | `json`)
```json5
{
logging: { level: "info", file: "/tmp/clawdis/clawdis.log" }
logging: {
level: "info",
file: "/tmp/clawdis/clawdis.log",
consoleLevel: "info",
consoleStyle: "pretty"
}
}
```

View File

@@ -1,3 +1,10 @@
---
summary: "Logging surfaces, file logs, WS log styles, and console formatting"
read_when:
- Changing logging output or formats
- Debugging CLI or gateway output
---
# Logging
Clawdis has two log “surfaces”:
@@ -53,3 +60,24 @@ clawdis gateway --verbose --ws-log compact
# show all WS traffic (full meta)
clawdis gateway --verbose --ws-log full
```
## Console formatting (subsystem logging)
Clawdis formats console logs via a small wrapper on top of the existing stack:
- **tslog** for structured file logs (`src/logging.ts`)
- **chalk** for colors (`src/globals.ts`)
The console formatter is **TTY-aware** and prints consistent, prefixed lines.
Subsystem loggers are created via `createSubsystemLogger("gateway")`.
Behavior:
- **Subsystem prefixes** on every line (e.g. `[gateway]`, `[canvas]`, `[tailscale]`)
- **Color only when TTY** (`process.stdout.isTTY` + `NO_COLOR` respected)
- **Sub-loggers by subsystem** (auto prefix + structured field `{ subsystem }`)
- **`logRaw()`** for QR/UX output (no prefix, no formatting)
- **Console styles** (e.g. `pretty | compact | json`)
- **Console log level** separate from file log level (file keeps full detail)
This keeps existing file logs stable while making interactive output scannable.