Skip to content

Stop logging "Rendering" twice per template at debug level on Rails 7.2 to 8.1 - #59

Merged
PetrHeinz merged 3 commits into
mainfrom
claude/view-listener-cleanup
Oct 2, 2026
Merged

PetrHeinz merged 3 commits into
mainfrom
claude/view-listener-cleanup

Conversation

@PetrHeinz

@PetrHeinz PetrHeinz commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

At debug level, Rails 7.2, 8.0 and 8.1 apps log every template render twice as "Rendering …", next to our single "Rendered …" line. Rails 7.1 and edge log none, which is what the subscriber intends. Evidence: one request in this repo's spec app on Rails 8.1.4 at debug level logs Rendering spec/support/rails/templates/template.html twice, then Rendered spec/support/rails/templates/template.html (0.1ms).

Since Rails 7.1, ActionView::LogSubscriber.attach_to subscribes two ActionView::LogSubscriber::Start listeners (template and layout) next to the subscriber, and those log the "Rendering" lines. LogtailLogSubscriber.attach_to removes them after calling super, but it looks them up with listeners_for, which skips silenced listeners. Rails 7.2 made Start silenceable (logger.nil? || !logger.debug?), and ActionView::Base.logger is still nil when the integration runs at boot. So nothing is found, and both Rails' own pair and the pair our super call adds stay subscribed.

  • Look the listeners up with all_listeners_for where ActiveSupport has it (7.1+), falling back to listeners_for.
  • Collect them into a new array with flat_map instead of concat-ing onto the first lookup: all_listeners_for returns the notifier's cached array, so concat would write into its cache.
  • Tests: after boot no Start listener is left for render_template.action_view and render_layout.action_view, and a request at debug level logs one "Rendered" line and no "Rendering" line.

Behaviour and compatibility:

  • At debug level on Rails 7.2 to 8.1 the "Rendering …" lines are gone, as on Rails 7.1 and edge. On Rails 7.0 and older the subscriber already drops them through its no-op log_rendering_start.
  • Nothing changes at info level and above, where Start logs nothing anyway, or on other Rails versions.

Targets the logtail-rails 0.2.15 patch release. No dependencies on the other gems.

Commits and CI:

  • Expect real response durations in the request specs is unrelated test maintenance that every logtail-rails PR needs right now: logtail-rack 0.2.8 times responses with the monotonic clock, which Timecop doesn't freeze, so three specs expecting "in 0.0ms" fail on every CI leg (main's last run still resolved logtail-rack 0.2.7). Keep Rails requests and their logs working with json 3 on Rails 8.0 and older #62 carries the identical commit, so the two merge cleanly in either order.
  • The tests commit is expected to be red on CI, on the Rails 7.2, 8.0 and 8.1 legs. The fix commit follows it.

🤖 Generated with Claude Code

PetrHeinz and others added 3 commits October 1, 2026 18:37
logtail-rack 0.2.8 times responses with the monotonic clock, which Timecop
doesn't freeze, so "Completed 200 OK in 0.0ms" no longer holds. The last CI
run on main still resolved logtail-rack 0.2.7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since Rails 7.1, ActionView::LogSubscriber.attach_to subscribes
ActionView::LogSubscriber::Start listeners that log "Rendering ..." at debug
level. The integration removes them, but on Rails 7.2 to 8.1 they survive,
so every template render logs "Rendering" twice at debug level.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rails 7.2 made ActionView::LogSubscriber::Start silenceable, and it counts
as silenced while ActionView::Base.logger is nil, as it is at boot.
listeners_for skips silenced listeners, so the cleanup in attach_to found
none and every render logged "Rendering" twice at debug level.

Look them up with all_listeners_for where ActiveSupport has it, and collect
them with flat_map: all_listeners_for returns the notifier's cached array,
which concat would modify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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