From d406d3a05813943f9266631a727fa396fc86223d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 18 Dec 2025 13:27:45 +0000 Subject: [PATCH] Gateway: optimize ws logs in normal mode --- docs/logging.md | 55 +++++++++++++++++++++++ src/cli/gateway-cli.ts | 13 ++++-- src/gateway/server.ts | 95 +++++++++++++++++++++++++++++++++++++-- src/gateway/ws-logging.ts | 6 ++- 4 files changed, 160 insertions(+), 9 deletions(-) create mode 100644 docs/logging.md diff --git a/docs/logging.md b/docs/logging.md new file mode 100644 index 000000000..05209c3af --- /dev/null +++ b/docs/logging.md @@ -0,0 +1,55 @@ +# Logging + +Clawdis has two log “surfaces”: + +- **Console output** (what you see in the terminal / Debug UI). +- **File logs** (JSON lines) written by the internal logger. + +## File-based logger + +Clawdis uses a file logger backed by `tslog` (`src/logging.ts`). + +- Default rolling log file is under `/tmp/clawdis/` (one file per day): `clawdis-YYYY-MM-DD.log` +- The log file path and level can be configured via `~/.clawdis/clawdis.json`: + - `logging.file` + - `logging.level` + +The file format is one JSON object per line. + +## Console capture + +The CLI entrypoint enables console capture (`src/index.ts` calls `enableConsoleCapture()`). +That means every `console.log/info/warn/error/debug/trace` is also written into the file logs, +while still behaving normally on stdout/stderr. + +## Gateway WebSocket logs + +The gateway prints WebSocket protocol logs in two modes: + +- **Normal mode (no `--verbose`)**: only “interesting” RPC results are printed: + - errors (`ok=false`) + - slow calls (default threshold: `>= 50ms`) + - parse errors +- **Verbose mode (`--verbose`)**: prints all WS request/response traffic. + +### WS log style + +`clawdis gateway` supports a per-gateway style switch: + +- `--ws-log auto` (default): normal mode is optimized; verbose mode uses compact output +- `--ws-log compact`: compact output (paired request/response) when verbose +- `--ws-log full`: full per-frame output when verbose +- `--compact`: alias for `--ws-log compact` + +Examples: + +```bash +# optimized (only errors/slow) +clawdis gateway + +# show all WS traffic (paired) +clawdis gateway --verbose --ws-log compact + +# show all WS traffic (full meta) +clawdis gateway --verbose --ws-log full +``` diff --git a/src/cli/gateway-cli.ts b/src/cli/gateway-cli.ts index 71a249298..dedbde667 100644 --- a/src/cli/gateway-cli.ts +++ b/src/cli/gateway-cli.ts @@ -58,8 +58,8 @@ export function registerGatewayCli(program: Command) { .option("--verbose", "Verbose logging to stdout/stderr", false) .option( "--ws-log