{"action":"closed","issue":{"url":"https://api.github.com/repos/plataformatec/faraday-http-cache/issues/20","labels_url":"https://api.github.com/repos/plataformatec/faraday-http-cache/issues/20/labels{/name}","comments_url":"https://api.github.com/repos/plataformatec/faraday-http-cache/issues/20/comments","events_url":"https://api.github.com/repos/plataformatec/faraday-http-cache/issues/20/events","html_url":"https://github.com/plataformatec/faraday-http-cache/issues/20","id":17353153,"number":20,"title":"ActiveSupport Notification support","user":{"login":"teamon","id":8083,"avatar_url":"https://avatars.githubusercontent.com/u/8083?v=3","gravatar_id":"","url":"https://api.github.com/users/teamon","html_url":"https://github.com/teamon","followers_url":"https://api.github.com/users/teamon/followers","following_url":"https://api.github.com/users/teamon/following{/other_user}","gists_url":"https://api.github.com/users/teamon/gists{/gist_id}","starred_url":"https://api.github.com/users/teamon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/teamon/subscriptions","organizations_url":"https://api.github.com/users/teamon/orgs","repos_url":"https://api.github.com/users/teamon/repos","events_url":"https://api.github.com/users/teamon/events{/privacy}","received_events_url":"https://api.github.com/users/teamon/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":8,"created_at":"2013-07-29T17:50:15Z","updated_at":"2015-04-04T15:42:38Z","closed_at":"2015-04-04T15:42:38Z","body":"I'd like to display log information about external http requests in rails app. Right now I'm doing something like this:\r\n\r\n```ruby\r\nclass FaradayInstrumentation < Faraday::Middleware\r\n  dependency 'active_support/notifications'\r\n\r\n  def call(env)\r\n    ActiveSupport::Notifications.instrument('external.faraday', env) do\r\n      @app.call(env)\r\n    end\r\n  end\r\nend\r\n\r\nMyApi.configure(...) do |c|\r\n  c.use FaradayInstrumentation\r\n  c.response :raise_error\r\nend\r\n\r\n```\r\n\r\nand then\r\n\r\n\r\n```ruby\r\nActiveSupport::Notifications.subscribe('external.faraday') do |name, starts, ends, _, env|\r\n  url = env[:url]\r\n  http_method = env[:method].to_s.upcase\r\n  duration = (ends - starts)*1000\r\n  Rails.logger.info '[%s] %s %s (%.3f ms)' % [url.host, http_method, url.request_uri, duration]\r\n  $statsd.timing(\"external.http\", duration, :tags => [\r\n    \"path:#{url.path}\", \"target:#{url.host}\", \"method:#{http_method}\"\r\n  ])\r\nend\r\n```\r\n\r\nBesides statsd measurements it gives me line in logs like:\r\n\r\n```\r\n[some.host.com] GET /some/path (143.494 ms)\r\n```\r\n\r\nI know faraday-http-cache has `:logger` options, but that by default gives me two lines in logs. The prefect logs would be like:\r\n\r\n```\r\n[some.host.com] GET /some/path (fresh)\r\n[some.host.com] GET /some/path (143.494 ms, miss)\r\n```\r\n\r\netc. What's even more important is sending event to statsd, which in case of cache fresh could be just skipped. \r\n\r\nIdeally information about cache action/status would be put in `env` hash which is accessible in all middlewares (and in my instrumentation hook).\r\n\r\nAny thoughts?"}}