Broadcast #silence on ActiveSupport::Logger #25341

Merged
merged 2 commits into from Jun 10, 2016

Conversation

Projects
None yet
5 participants
@kmcphillips
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

This comment has been minimized.

Show comment
Hide comment
@rails-bot

rails-bot 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.

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

This comment has been minimized.

Show comment
Hide comment
@kmcphillips

kmcphillips Jun 10, 2016

Contributor

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...

Contributor

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...

- 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.

@kmcphillips

kmcphillips Jun 10, 2016

Contributor

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

@kmcphillips

kmcphillips Jun 10, 2016

Contributor

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

@kmcphillips

This comment has been minimized.

Show comment
Hide comment
@kmcphillips

kmcphillips Jun 10, 2016

Contributor

Tests green 💚

Contributor

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.

@kmcphillips

kmcphillips Jun 10, 2016

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 Jun 10, 2016

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.

@rafaelfranca rafaelfranca merged commit 1f452f9 into rails:master Jun 10, 2016

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

Merge pull request #25341 from kmcphillips/master
Broadcast #silence on ActiveSupport::Logger
@rafaelfranca

This comment has been minimized.

Show comment
Hide comment
@rafaelfranca

rafaelfranca Jun 10, 2016

Member

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

Member

rafaelfranca commented Jun 10, 2016

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

@kmcphillips

This comment has been minimized.

Show comment
Hide comment
@kmcphillips

kmcphillips Jun 10, 2016

Contributor

Yep! I'll do that right away.

Contributor

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