rails/rails — pull request #15164 by notEthan (2014-05-18 03:26:12+00:00)
Title: update LogTailer to tail logs when the request body is closed rather than when the middleware itself returns

I encountered log tailing failing to show logs from some middleware in a timely manner (not showing up until the next request), which I found was due to the middleware doing logging when the request closes rather than when the middleware returns. this is not uncommon, e.g. rack's own logger does this (https://github.com/rack/rack/blob/master/lib/rack/commonlogger.rb#L35)

to fix this I changed the LogTailer to operate when the request body is closed rather than when the middleware itself returns, using Rack::BodyProxy.