I have a download action in my controller that is logged when the user clicks on the download link. Is there any way to track how long it took for the download to complete or at least that it was successful?
Here is the download action in the controller (Rails 3.2.8):
def download
send_file @download.attachment.path, :filename => @download.attachment_file_name,
:content_type => @download.attachment_content_type
DownloadsLog.debug "log details here! -- at #{Time.now}"
end
downloads_log.rb model
class DownloadsLog
def self.debug(message=nil)
@@downloads_log ||= Logger.new("#{Rails.root}/log/downloads.log", 10, 1024000)
@@downloads_log.debug(message) unless message.nil?
end
end
Maybe it’s not possible but I thought I would ask if anyone had any ideas…
Thanks!
In Rails 3, wrap a section of code in a block, and supply it to the method
benchmark.In your log, you’ll see a line that indicates how long your block took to execute:
You can even use this in a view: