Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broadcast #silence on ActiveSupport::Logger #25341

Merged
merged 2 commits into from Jun 10, 2016
Merged

Conversation

@kmcphillips
Copy link
Contributor

kmcphillips commented Jun 10, 2016

@rafaelfranca @tenderlove @sgrif

Context

I pulled in config.assets.quiet to sprockets-rails in rails/sprockets-rails#355

Problem

I found that in our rails app it would silence the asset requests correctly into log/development.log, but it would still output the request into the rails console.

The reason for this is that we use broadcasting to delegate the logged message to both the console and the log file. But without delegating the call to #silence down it only silences the first logger, so in this case the log file but not console.

Solution

The broadcasting module needs to properly delegate #silence along with other methods to the loggers.

Also took the opportunity to rewrite the tests entirely, increase coverage, and properly test #silence.

Not sure what the release path is for this. The quiet assets feature fails to work without this fix.

@rails-bot
Copy link

rails-bot commented Jun 10, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @chancancode (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@kmcphillips kmcphillips force-pushed the kmcphillips:master branch Jun 10, 2016
@kmcphillips
Copy link
Contributor Author

kmcphillips commented Jun 10, 2016

Rebased in upstream/master and found there are no tests for local_level delegation. And it fails without errors because of the respond_to?(:local_level=). Writing tests...

@kmcphillips kmcphillips force-pushed the kmcphillips:master branch Jun 10, 2016
def add(*args)
@adds << args
def add(message_level, message=nil, progname=nil, &block)
@adds << [message_level, message, progname] if message_level >= local_level

This comment has been minimized.

Copy link
@kmcphillips

kmcphillips Jun 10, 2016

Author Contributor

Don't love this, because we're basically testing the behaviour of a logger of by reimplementing some of the logic.

@kmcphillips kmcphillips force-pushed the kmcphillips:master branch to 83f9cdb Jun 10, 2016
@kmcphillips
Copy link
Contributor Author

kmcphillips commented Jun 10, 2016

Tests green 💚

logger.debug "foo"
assert_equal 'foo', log1.adds.first[2]
assert_equal 'foo', log2.adds.first[2]
Logger::Severity.constants.each do |level_name|

This comment has been minimized.

Copy link
@kmcphillips

kmcphillips Jun 10, 2016

Author Contributor

If this is too clever I can remove it. It will just mean copying the same 5 line test 6 times for each log level.

@kmcphillips kmcphillips force-pushed the kmcphillips:master branch to 83f9cdb Jun 10, 2016
@rafaelfranca rafaelfranca merged commit 1f452f9 into rails:master Jun 10, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
rafaelfranca added a commit that referenced this pull request Jun 10, 2016
Broadcast #silence on ActiveSupport::Logger
@rafaelfranca
Copy link
Member

rafaelfranca commented Jun 10, 2016

Thanks! Do you want to backport it to Rails 4.2?

@kmcphillips
Copy link
Contributor Author

kmcphillips commented Jun 10, 2016

Yep! I'll do that right away.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.