Skip to content

DevConsole: log streamer with file/tcp/stderr sinks#90

Merged
meszmate merged 1 commit intomainfrom
feature/dev-console
Apr 23, 2026
Merged

DevConsole: log streamer with file/tcp/stderr sinks#90
meszmate merged 1 commit intomainfrom
feature/dev-console

Conversation

@meszmate
Copy link
Copy Markdown
Owner

@meszmate meszmate commented Apr 21, 2026

Summary

Solves the perennial TUI debugging problem: stdout is owned by the renderer, so `std.debug.print` would garble the screen. `DevConsole` routes structured log events to a separate sink so a developer can run the TUI in one terminal and `tail -f` (or `nc`) the log stream in another. Modeled on `textual console`.

Sinks

Sink Use it with
`.file` `tail -f path.log` in another terminal
`.tcp` `nc localhost ` — multiple viewers can connect simultaneously
`.stderr` when stderr is redirected to a file or pipe

Multiple sinks can be added — events fan out to all of them.

API

```zig
var console = zz.DevConsole.init(allocator);
defer console.deinit();
try console.addSink(.{ .file = "/tmp/myapp.log" });
try console.addSink(.{ .tcp = .{ .port = 9999 } });
console.setMinLevel(.warn);

console.info("starting up", .{});
console.warn("retry {d}", .{n});
console.err("connection lost", .{});
```

Each event has a level (trace/debug/info/warn/err) and a timestamp. Mutex-guarded so it's safe to call from any thread. Distinct from the existing `Logger` which is a single-file convenience type without levels or fan-out.

Test plan

  • `zig build test` — added 3 tests covering file sink output, min-level filtering, and level rank ordering
  • Manual: `zig build run-someapp` in one terminal, `tail -f /tmp/myapp.log` in another, verify events appear
  • Manual: `.tcp` sink with two simultaneous `nc` viewers

Solves the perennial TUI debugging problem: stdout is owned by the
renderer, so std.debug.print would garble the screen. DevConsole routes
structured log events to a separate sink so a developer can run the TUI
in one terminal and tail -f (or nc) the log stream in another.

Sinks:
  * .file   — append to a log file (pair with tail -f)
  * .tcp    — listen on a port (pair with nc localhost <port>)
  * .stderr — write to stderr when stderr is redirected away

Each event has a level (trace/debug/info/warn/err) and a timestamp.
Multi-sink fan-out, mutex-guarded for thread safety, and a min_level
filter for adjustable verbosity at runtime.
@meszmate meszmate merged commit c25b134 into main Apr 23, 2026
9 checks passed
@meszmate meszmate deleted the feature/dev-console branch April 24, 2026 13:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant