Log broadcasts once per event instead of once per subscriber (#73)#107
Open
russ wants to merge 1 commit into
Open
Log broadcasts once per event instead of once per subscriber (#73)#107russ 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>
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 #73.
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