Skip to main content

Module log_stream

Module log_stream 

Source
Expand description

Streaming a running dataflow’s output to a terminal (blueprint §17: astrs run “streams logs to the terminal”; astrs logs -f does the same over the coordinator link).

  embedded daemon ──DaemonEvent──► TerminalLogSink ──bounded──► printer task
  (event loop)                     (never blocks,               (owns stdout)
                                    counts drops)

  coordinator ──LogFrame──────────────────────────────────────► same printer

§The sink must never block the event loop

astrs_daemon::health::ReportSink::report is called from inside the daemon’s merged event loop, and its contract says so: “reporting must never block the event loop and must never fail it”. A sink that took a lock around a write! to a terminal would stall every node on the machine behind a slow pipe. TerminalLogSink therefore does the one thing that cannot stall: a try_send into a bounded channel, with a counter for what did not fit. A separate task owns the sink and does the formatting and the writing.

Bounded rather than unbounded on purpose: an unbounded channel in front of a terminal that has stopped being read is an out-of-memory bug with extra steps. Dropping the oldest news under sustained overload — and saying how much was dropped when the stream ends — is the behavior a log tail should have.

Structs§

LogFilter
Which items reach the terminal.
LogStyle
How the terminal is painted.
TerminalLogSink
The ReportSink astrs run installs on its embedded daemon.

Enums§

StreamItem
One thing worth printing.

Constants§

STREAM_CAPACITY
How many items may be queued between the daemon’s event loop and the printer before the oldest news starts being dropped.

Functions§

level_at_least
Whether level is at least as severe as floor.
parse_level
Parses a --level argument, accepting the spellings a user types.
prefix_width
The widest node name in a manifest, so the [node] column is sized before the first line is printed rather than jittering as nodes appear.
print_stream
Drains receiver onto out until the stream ends, returning how many items were printed.
render
Formats one item as the line a terminal shows.