Sha256: dc0673875767f8681b51944c2454f29ae566d1fe4a22f3b520f57c2cca6b89bb

Contents?: true

Size: 1.44 KB

Versions: 25

Compression:

Stored size: 1.44 KB

Contents

module HTTParty
  module Logger
    class CurlLogger #:nodoc:
      TAG_NAME = HTTParty.name
      OUT = ">"
      IN = "<"

      attr_accessor :level, :logger, :current_time

      def initialize(logger, level)
        @logger = logger
        @level  = level.to_sym
      end

      def format(request, response)
        messages        = []
        time            = Time.now.strftime("%Y-%m-%d %H:%M:%S %z")
        http_method     = request.http_method.name.split("::").last.upcase
        path            = request.path.to_s

        messages << print(time, OUT, "#{http_method} #{path}")

        if request.options[:headers] && request.options[:headers].size > 0
          request.options[:headers].each do |k, v|
            messages << print(time, OUT, "#{k}: #{v}")
          end
        end

        messages << print(time, OUT, request.raw_body)
        messages << print(time, OUT, "")
        messages << print(time, IN, "HTTP/#{response.http_version} #{response.code}")

        headers = response.respond_to?(:headers) ? response.headers : response
        response.each_header do |response_header|
          messages << print(time, IN, "#{response_header.capitalize}: #{headers[response_header]}")
        end

        messages << print(time, IN, "\n#{response.body}")

        @logger.send @level, messages.join("\n")
      end

      def print(time, direction, line)
        "[#{TAG_NAME}] [#{time}] #{direction} #{line}"
      end
    end
  end
end

Version data entries

25 entries across 24 versions & 7 rubygems

Version Path
alloy_sdk-0.1.0 vendor/bundle/ruby/3.0.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
alloy_sdk-0.1.0 vendor/bundle/ruby/2.6.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
httparty-0.13.5 lib/httparty/logger/curl_logger.rb
httparty-0.13.4 lib/httparty/logger/curl_logger.rb
httsoiree-0.13.3 lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.9 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
httparty-0.13.3 lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.8 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.7 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
httparty-0.13.2 lib/httparty/logger/curl_logger.rb
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.6 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.5 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.4 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.3 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.2 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
allegro_api_client-0.0.1 gems/ruby/2.1.0/gems/httparty-0.13.1/lib/httparty/logger/curl_logger.rb
httsoiree-0.13.1.1 lib/httparty/logger/curl_logger.rb
httsoiree-0.13.1 lib/httparty/logger/curl_logger.rb
httparty-enterprise-edition-0.13.1.1 lib/httparty/logger/curl_logger.rb