rails/rails — pull request #13651 by cainlevy (2014-01-09 18:59:20+00:00)
Title: clean up remaining log flushing support

Currently, `ActiveSupport::TaggedLogging#flush` will clear out any tags before trying to call flush on the wrapped `Logger`, which no longer happens. The tag clearing logic appears to have been intentional when it was [originally committed](https://github.com/rails/rails/commit/6c126015a676c376f1646713fbb739049a783238#diff-f5b84c8292ccf226ce319abbd6953fa0R40) but we have been unable to imagine the use case.

This seems like an odd coupling. The coupled behaviors (clearing tags + flushing buffered logging to file) no longer appear to benefit Rails' own code, but can cause bugs when other code attempts to use `Rails.logger.tagged{...}`.

### Rails' Code

The only place where I can find Rails calling `#flush` is via [`ActiveSupport::LogSubscriber.flush_all!`](https://github.com/rails/rails/blob/master/activesupport/lib/active_support/log_subscriber.rb#L69). And the only place where I can find Rails calling that is from [`Rails::Rack::Logger#call_app`](https://github.com/rails/rails/blob/master/railties/lib/rails/rack/logger.rb#L45).

In this case, the `#flush` logic is redundant because the next operation after `#call_app` - when tags are in use - is to pop the request's tags back off the stack. That ends up being a noop because the stack was just emptied.

### Our Bug

I added a tag to our `Delayed::Job` workers so I could associate output with specific processes. I noticed that the tag was disappearing shortly after the process started, and eventually tracked it down to a particular job using the urbanairship gem, which still [flushes after logging](https://github.com/groupon/urbanairship/blob/master/lib/urbanairship.rb#L171).

### The Cleanup

Minimally, I would like to remove `ActiveSupport::TaggedLogging#flush`.

But at that point, I think there is no remaining logger that will `respond_to?(:flush)`, which means that `ActiveSupport::LogSubscriber#flush_all!` is no longer effective and can also be removed. So I've cleaned up all the tendrils.