Skip to content

Conversation

@lucthev
Copy link
Contributor

@lucthev lucthev commented Nov 25, 2024

Background

In the app I'm working on, we've (mostly) silenced logs in CI via

# config/environments/test.rb
if ENV['CI']
  config.log_level = :fatal
end

There are some tests that explicitly test logging, though, so for the duration of those test we drop the log level down back down to :info.

While upgrading this app from Rails 7 to Rails 7.1, we saw some odd failures in these tests — both the Rails-default logs and the rails_semantic_logger logs were being printed. It seems to be due to the changes made in rails/rails#45796 to the listeners_for method, which rails_semantic_logger uses to unsubscribe existing log subscribers. In short:

  • With log_level = :fatal, when rails_semantic_logger is first loaded, listeners_for doesn't return the Rails-default log subscribers, since they're currently silenced
  • When we drop the log level back down, those listeners are now un-silenced, and output their logs

Description of changes

This PR uses all_listeners_for, where available, to ensure that currently-silenced subscribers also get unsubscribed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@reidmorrison reidmorrison merged commit 0c09805 into reidmorrison:master Jul 24, 2025
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.

2 participants