Skip to content

Instantly share code, notes, and snippets.

@vicentereig
Forked from huacnlee/grape_runtime_log.rb
Last active August 29, 2015 14:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save vicentereig/136bddb741fb2ebe8151 to your computer and use it in GitHub Desktop.
require 'grape'
class API < Grape::API
before do
@log_start_t = Time.now
Rails.logger.info " Parameters: #{params.to_hash.except("route_info")}"
end
after do
@log_end_t = Time.now
total_runtime = ((@log_end_t - @log_start_t) * 1000).round(1)
db_runtime = (ActiveRecord::RuntimeRegistry.sql_runtime || 0).round(1)
Rails.logger.info "Completed in #{total_runtime}ms (ActiveRecord: #{db_runtime}ms)"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment