获取带有 Unicorn 响应大小的响应日志

Get response logs with response size for Unicorn

如何获取我的 rails 应用程序每次点击的日志以及每次响应的大小?

我得到了每个 api 命中的日志和一个显示 "Completed 200 OK in 69.5ms" 的响应日志。但是我需要每个响应的大小。

你有 nginx 吗?或使用类似的东西

class ApplicationController < ActionController::Base
  after_action :print_size

  def print_size
    Rails.logger.info "#{controller_name}##{action_name}: #{response.body.size}"
  end
end