Skip to content

Remove Rails' event reporter log subscribers on Rails 8.2+ - #412

Merged
johnnagro merged 2 commits into
masterfrom
fix-rails-82-event-reporter-subscribers
Nov 14, 2026
Merged

johnnagro merged 2 commits into
masterfrom
fix-rails-82-event-reporter-subscribers

Conversation

@johnnagro

Copy link
Copy Markdown
Collaborator

Fixes #407.

Problem

rails/rails#55900 changed ActionController::LogSubscriber and ActionView::LogSubscriber to inherit from ActiveSupport::EventReporter::LogSubscriber. They are now subscribed to ActiveSupport.event_reporter, not ActiveSupport::Notifications. Lograge.remove_existing_log_subscriptions only looks in ActiveSupport::LogSubscriber.log_subscribers, so on Rails main it finds nothing to remove. Rails' Processing by … / Completed 200 OK … lines are logged next to lograge's line.

lograge's own subscriber is not affected. process_action.action_controller is still sent through ActiveSupport::Notifications.

Change

  • remove_existing_log_subscriptions now also calls ActiveSupport.event_reporter.unsubscribe for ActionController::LogSubscriber and ActionView::LogSubscriber. It only does this when those classes inherit from ActiveSupport::EventReporter::LogSubscriber. Removal for Rails ≤ 8.1 is unchanged.
  • Specs: the removal tests now pick the right setup for the Rails version. On 8.2+ they check that the Rails subscribers are removed from the event reporter, that unrelated subscribers are kept, and they re-subscribe the Rails ones afterwards.
  • Specs: the two RecordNotFound 404 specs no longer change ActionDispatch::ExceptionWrapper.rescue_responses in place, because Rails main now freezes it. That was a separate cause of the edge CI failures.
  • CHANGELOG entry under Unreleased.

Testing

Rails master this branch
edge (8.2.0.alpha) 6 failures 159 examples, 0 failures
8.1 / 7.1 / 6.1 — 161 examples, 0 failures

Rubocop reports no offenses.

Notes

  • The Rails PR treats these subscribers as private API, so this could need another change before 8.2 is released.
  • Edge CI jobs run with continue-on-error, which is why these failures went unnoticed. It might be worth making edge failures visible as a follow-up.
  • Out of scope: Rails 8.2 also moved ActionDispatch::LogSubscriber to the event reporter. lograge has never removed that one, so route-level redirects still produce Rails' own log lines, the same as on earlier versions.

Rails 8.2 (rails/rails#55900) moved ActionController::LogSubscriber and
ActionView::LogSubscriber onto ActiveSupport::EventReporter::LogSubscriber,
subscribed to ActiveSupport.event_reporter rather than
ActiveSupport::Notifications. remove_existing_log_subscriptions no longer
found them, so Rails' "Processing by" / "Completed" lines were logged
alongside lograge's line.

Also unsubscribe these classes from ActiveSupport.event_reporter when they
are event reporter log subscribers. The Notifications-based removal for
earlier Rails versions is unchanged.

Update the specs for both subscriber systems, and stop mutating
ExceptionWrapper.rescue_responses in place, since Rails main freezes it.

Fixes #407
…pecs

Mark the two new event reporter helpers as private class methods so they
don't become part of Lograge's public API, and drop the redundant
ActiveSupport.respond_to?(:event_reporter) check.

Restore ActionDispatch::ExceptionWrapper.rescue_responses after the 404
specs so the RecordNotFound mapping doesn't leak into other examples.
@johnnagro
johnnagro merged commit a0721ae into master Nov 14, 2026
93 of 94 checks passed
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.

Rails main: Rails' request log lines are no longer removed

1 participant