Sha256: 28eb8889172f62721ed1eeff67dacf0075d64171997c8efd15aadda1182ef950

Contents?: true

Size: 1.02 KB

Versions: 12

Compression:

Stored size: 1.02 KB

Contents

require 'faraday_middleware/response_middleware'

module ZendeskAPI
  module Middleware
    module Response
      # Faraday middleware to handle logging
      # @private
      class Logger < Faraday::Response::Middleware
        def initialize(app, logger = nil)
          super(app)
          @logger = logger || begin
            require 'logger'
            ::Logger.new(STDOUT)
          end
        end

        def call(env)
          @logger.info "#{env[:method]} #{env[:url].to_s}"
          @logger.debug dump_debug(env, :request_headers)
          super
        end

        def on_complete(env)
          @logger.info("Status #{env[:status].to_s}")
          @logger.debug dump_debug(env, :response_headers)
        end

        private

        def dump_debug(env, headers_key)
          info = env[headers_key].map { |k, v| "  #{k}: #{v.inspect}" }.join("\n")
          unless env[:body].nil?
            info.concat("\n")
            info.concat(env[:body].inspect)
          end
          info
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
zendesk_api-0.3.2 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.3.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.3.0 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.2.6 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.2.5 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.2.4 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.2.2 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.2.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.1.11 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.1.10 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.1.9 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-0.1.8 lib/zendesk_api/middleware/response/logger.rb