Skip to content

friglet: colour the console log by stdout, the stream it is written to (SNB-682) - #56

Closed
setavenger wants to merge 4 commits into
integrationfrom
snb-682-console-colour-stdout
Closed

setavenger wants to merge 4 commits into
integrationfrom
snb-682-console-colour-stdout

Conversation

@setavenger

@setavenger setavenger commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #53; review only the commits after it.

Fixes SNB-682 (Bug). Part of the friglet cleanup (SNB-661).

The bug

The console log is written to stdout (tracing-subscriber's default writer), but init_logging decided whether to colour it by checking whether stderr is a terminal. Running friglet > out.log from a terminal therefore wrote ANSI escapes into the file.

The fix (minimal)

  • .with_ansi(stdout().is_terminal()), and .with_writer(std::io::stdout) so the stream that is checked and the stream that is written are named in the same place. The writer was already stdout, so where lines go does not change.
  • The two comments that said stderr now say stdout, and so does the "cannot write the log file; logging to stdout only" warning (second commit, from review). No tray or friglet-ui code matches that text.

Behaviour changes only when stdout and stderr go to different places. A terminal still gets colour. A tray-spawned daemon (stdout and stderr both piped) still gets none.

Test

friglet/tests/console_colour.rs (Linux only). It runs the real binary with a config error inside a pseudo-terminal from util-linux script, and skips with a message if script is missing (ubuntu-24.04 CI has it).

  1. stdout + stderr on the terminal → the output contains escapes.
  2. stdout redirected to a file, stderr on the terminal → the file has the log line and no escapes.

Without the fix (main.rs from #53, same test):

panicked at friglet/tests/console_colour.rs:60:5:
no ANSI escapes in a file: "\u{1b}[2m2026-10-03T09:11:12.880993Z\u{1b}[0m \u{1b}[31mERROR\u{1b}[0m friglet exited with an error: invalid network `flarkchain`: ..."
test result: FAILED. 0 passed; 1 failed

With the fix: test result: ok. 1 passed.

Verification

Not in this PR

README (README.md:186,199-200) and AGENTS.md ("The daemon itself only emits ANSI when stderr is a TTY") still say stderr; fixing them belongs to the docs PR (SNB-674).

setavenger and others added 3 commits October 3, 2026 08:47
The Electrum server built the same things in several places. One copy
of each now:

- notification(): the JSON-RPC notification line (was written out four
  times); sp_subscription(): the SP subscription object and its
  notification, shared by the push task and the subscribe handler.
- invalid_param(): the -32602 answer for a missing or mistyped first
  parameter (block.header, scripthash.subscribe/get_history,
  transaction.get); the messages are unchanged.
- save_header_sidecar(): the header-sidecar write after a backfill and
  after a reorg.
- Peer::header_by_hash() takes one hash (its only caller passed a
  one-element slice) and returns only a header with that hash, so the
  two re-checks of the same hash in ChainSource::header and
  backfill_header go.
- relay: connect_settled() (connect + settle, the 2 s literal is now
  p2p::SETTLE_WAIT, also used by ChainSource::fee_filter),
  Candidate::wire_tx() and Signals::announce() replace two or three
  copies each.
- index_unconfirmed_tx: two match arms that both did nothing are one
  condition.
- Two tests build their request with call() like the others.

The bytes on the wire are unchanged: a scripted session of 52 requests
and 8 push batches gives byte-identical output before and after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…(SNB-664)

Leftovers from the live scanner swap and from earlier refactors:

- ControlCtx keeps the Electrum index and the label addresses directly;
  the std Mutex around each was never written after the live
  rebuild-and-swap went away (#29). The Start comment that still
  described the swap is fixed.
- One-line wrappers around friglet-ipc are gone (default_config_path,
  default_key_file, write_config_file, write_key_file, replace_scan_key);
  apply() writes the key it already parsed instead of having
  replace_scan_key parse it again.
- pick_tip was `oracle.or(electrum)`; inlined, with its test.
- control's unix_now duplicated pending::now_secs.
- The key file's "first non-empty line" is read by one helper.
- ResolvedConfig no longer copies oracle_url, max_label_num, http_addr
  and electrum_addr out of `raw`.
- main no longer sets sp_start_height a second time right after
  rebuild_electrum_index_from_graph set it.
- control::run takes the ControlCtx instead of a generic handler; its
  only other user was get_status_roundtrip_over_control_socket, which
  repeated friglet-ipc's roundtrip test and every serve_ctx test.
- supervisor: stop_during_a_download_pauses_at_once repeated the
  cooperative-cancel tests and left a 30 s thread behind.
- fake_peer: the single-field Seen struct is a Vec.
- Stale comments: types.rs, the --oracle-url default, electrum::run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…o (SNB-682)

The console log goes to stdout (tracing-subscriber's default writer),
but whether it is coloured was decided by looking at stderr. Run from a
terminal with stdout redirected (`friglet > out.log`), the file got ANSI
escapes. The layer now checks stdout and names stdout as its writer, so
the two cannot drift apart again; the comments that said stderr say
stdout.

Nothing changes when both streams go to the same place: a terminal still
gets colour, and a tray-spawned daemon (both piped) still gets none.

New test (Linux, needs util-linux `script` for a pseudo-terminal; skips
without it): with stdout redirected to a file and stderr on the
terminal, the file has no escapes. It fails on the old code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s (SNB-682)

"cannot write the log file; logging to stderr only" was missed in the
first commit: the console log is written to stdout. No tray or friglet-ui
code matches this text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@setavenger

Copy link
Copy Markdown
Owner Author

Merged into integration through #70 on 2026-10-11 (the user live-tested the combined stack first). GitHub's stacked-PR merge rebased the stack, so this PR's commits landed with new IDs and GitHub can't mark it merged itself. The code is identical: integration now has the same tree as the tested branch friglet-deslop-live-test (08bf11d), which contains this PR's head. Closing as merged via #70.

@setavenger setavenger closed this Oct 11, 2026
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