Revisions
-
teamon revised this gist
Jun 25, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # config/initializers/instrumentation.rb # Subscribe to grape request and log with Rails.logger ActiveSupport::Notifications.subscribe('grape.request') do |name, starts, ends, notification_id, payload| -
teamon revised this gist
Jun 25, 2014 . 1 changed file with 26 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ # app/controllers/api/logger.rb class API::Logger def initialize(app) @app = app end def call(env) payload = { remote_addr: env['REMOTE_ADDR'], request_method: env['REQUEST_METHOD'], request_path: env['PATH_INFO'], request_query: env['QUERY_STRING'], x_organization: env['HTTP_X_ORGANIZATION'] } ActiveSupport::Notifications.instrument "grape.request", payload do @app.call(env).tap do |response| payload[:params] = env["api.endpoint"].params.to_hash payload[:params].delete("route_info") payload[:params].delete("format") payload[:response_status] = response[0] end end end end -
teamon created this gist
Jun 25, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,13 @@ # config/instrumentation.rb # Subscribe to grape request and log with Rails.logger ActiveSupport::Notifications.subscribe('grape.request') do |name, starts, ends, notification_id, payload| Rails.logger.info '[API] %s %s (%.3f ms) -> %s %s%s' % [ payload[:request_method], payload[:request_path], (ends-starts)*1000, (payload[:response_status] || "error"), payload[:x_organization] ? "| X-Org: #{payload[:x_organization]}" : "", payload[:params] ? "| #{payload[:params].inspect}" : "" ] end