A ActiveSupport::LogSubscriber
to log HTTP requests made by a Faraday client instance.
Add it to your Gemfile:
gem 'faraday-log-subscriber'
You have to use the :instrumentation
middleware from faraday_middleware
to
instrument your requests.
client = Faraday.new('https://api.github.com') do |builder|
builder.use :instrumentation
builder.adapter :net_http
end
client.get('repos/rails/rails')
# 'Faraday GET [200] (1026.9ms) https://api.github.com/repos/rails/rails'
If you use the faraday-http-cache
gem, an extra line will be logged regarding
the cache status of the requested URL:
client = Faraday.new('https://api.github.com') do |builder|
builder.use :instrumentation
builder.use :http_cache, instrumenter: ActiveSupport::Notifications
builder.adapter :net_http
end
client.get('repos/rails/rails')
client.get('repos/rails/rails')
# Faraday HTTP Cache [fresh] https://api.github.com/repos/rails/rails
# Faraday GET [200] (1.7ms) https://api.github.com/repos/rails/rails
Copyright (c) 2015 Plataformatec. See LICENSE file.