Search code examples
ruby-on-railsloggingunicorn

Get response logs with response size for Unicorn


How can I get the logs for each hit to my rails app with the size of each response?

I get the logs for each api hits and a response log which says "Completed 200 OK in 69.5ms". But I need the size of each response.


Solution

  • Do you have nginx by any chance? or use something like or similar

    class ApplicationController < ActionController::Base
      after_action :print_size
    
      def print_size
        Rails.logger.info "#{controller_name}##{action_name}: #{response.body.size}"
      end
    end