Log broadcasts once per event instead of once per subscriber (#73)#1
Closed
russ wants to merge 1 commit into
Closed
Log broadcasts once per event instead of once per subscriber (#73)#1russ wants to merge 1 commit into
russ wants to merge 1 commit into
Conversation
…able-cr#73 `Cable::Server#send_to_channels` logged a "transmitting" line inside the per-subscriber loop, so a single broadcast to a stream with N connected clients produced N identical log lines. A busy chat room could emit dozens of duplicate entries for one message, flooding production logs. Move the log outside the loop and emit a single line per broadcast that includes the number of subscribers it was delivered to. Skips logging entirely when there are no live subscribers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Reduces log noise by emitting a single "Transmitting ... to N subscribers" line per broadcast event instead of one line per subscriber in Cable::Server#send_to_channels.
Changes:
- Move the info log out of the per-subscriber loop and aggregate a
transmittedcount of live deliveries. - Skip the log entirely when no live subscribers received the message; pluralize "subscriber(s)" based on count.
- Add a spec capturing logs to assert exactly one info line is emitted for a broadcast with two subscribers.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/cable/server.cr | Track transmitted count and log a single aggregated info line after the fan-out loop. |
| spec/cable/server_spec.cr | New #send_to_channels spec verifies one info log per broadcast using log/spec capture. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Owner
Author
|
Superseded by cable-cr#107 — opened against the upstream repo instead. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Fixes cable-cr#73 (originally surfaced in production via the JoystickTV report).
Cable::Server#send_to_channelslogged the "transmitting" line inside the per-subscriber loop:So broadcasting one message to a stream with N connected clients produced N identical log lines. A chat room with 100 viewers logged
"hi"100 times; the only workaround wasCable::Logger.level = :none, which silences all Cable logging.Change
Move the log outside the loop and emit a single line per broadcast event, including the number of subscribers it was delivered to:
The redundant per-message broadcast is still logged once at the call site (
Channel#broadcast/.broadcast_to), so no information is lost.Tests
Added
spec/cable/server_spec.cr#send_to_channels— subscribes two connections to the same stream, captures logs, and asserts exactly one info line (... to 2 subscribers ...) is emitted. Full suite green (52 examples, 0 failures);amebaclean.Note
This changes the log line format (
<Class> transmitting <msg> (via streamed from <id>)→Transmitting <msg> to <n> subscribers (via streamed from <id>)). Anything grepping the old string will need updating.🤖 Generated with Claude Code