Last active
July 3, 2016 09:56
-
-
Save huacnlee/8312826 to your computer and use it in GitHub Desktop.
Output request time spend and parameters in log for Grape
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
created a gem for grape with exact this functionality, check it out: https://rubygems.org/gems/grape_logging
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And then, the output log will be: