Sha256: 65ef942b6cb221098cc9c97bdfeeda55324ac5fd95c9d7021133f30bdb582bd7

Contents?: true

Size: 997 Bytes

Versions: 55

Compression:

Stored size: 997 Bytes

Contents

module ZendeskAPI
  module Middleware
    module Response
      # Faraday middleware to handle logging
      # @private
      class Logger < Faraday::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)

          @app.call(env).on_complete do |env|
            @logger.info("Status #{env[:status].to_s}")
            @logger.debug dump_debug(env, :response_headers)
          end
        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

55 entries across 55 versions & 1 rubygems

Version Path
zendesk_api-1.15.0 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.14.4 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.14.2 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.14.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.14.0 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.13.4 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.13.3 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.13.2 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.13.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.12.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.12.0 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.7 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.6 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.5 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.4 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.3 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.2 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.1 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.11.0 lib/zendesk_api/middleware/response/logger.rb
zendesk_api-1.10.0 lib/zendesk_api/middleware/response/logger.rb