Sha256: 53191a93d75dbbc99009cb1893aaf8a082c96d3c9966d53d03a8b292ef5830da

Contents?: true

Size: 995 Bytes

Versions: 87

Compression:

Stored size: 995 Bytes

Contents

# frozen_string_literal: true

module HTTParty
  module Logger
    class ApacheFormatter #:nodoc:
      TAG_NAME = HTTParty.name

      attr_accessor :level, :logger

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

      def format(request, response)
        @request = request
        @response = response

        logger.public_send level, message
      end

      private

      attr_reader :request, :response

      def message
        "[#{TAG_NAME}] [#{current_time}] #{response.code} \"#{http_method} #{path}\" #{content_length || '-'} "
      end

      def current_time
        Time.now.strftime('%Y-%m-%d %H:%M:%S %z')
      end

      def http_method
        request.http_method.name.split('::').last.upcase
      end

      def path
        request.path.to_s
      end

      def content_length
        response.respond_to?(:headers) ? response.headers['Content-Length'] : response['Content-Length']
      end
    end
  end
end

Version data entries

87 entries across 86 versions & 4 rubygems

Version Path
harbr-0.1.81 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.80 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.79 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.78 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.77 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.76 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.75 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.74 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.73 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.72 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.71 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.70 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.69 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.68 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.67 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.66 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.65 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.64 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.63 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb
harbr-0.1.62 vendor/bundle/ruby/3.2.0/gems/httparty-0.21.0/lib/httparty/logger/apache_formatter.rb