Skip to content

Instantly share code, notes, and snippets.

@teamon
Last active September 8, 2021 03:45
Show Gist options
  • Select an option

  • Save teamon/e8ae16ffb0cb447e5b49 to your computer and use it in GitHub Desktop.

Select an option

Save teamon/e8ae16ffb0cb447e5b49 to your computer and use it in GitHub Desktop.
# 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
@guizmaii
Copy link

guizmaii commented Mar 8, 2016

Just for information, we used your idea in this gem : https://github.com/aserafin/grape_logging ;)

Thanks for the idea !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment