Sha256: 46c78a73b648b7c93d732bffaf007f79f5375f74785d240ee935253576847007

Contents?: true

Size: 1.16 KB

Versions: 43

Compression:

Stored size: 1.16 KB

Contents

require 'logger'

module Excon
  class LoggingInstrumentor

    def self.instrument(name, params = {})
      params = params.dup

      logger = params[:logger] || Logger.new($stderr)

      # reduce duplication/noise of output
      params.delete(:connection)
      params.delete(:stack)

      if params.has_key?(:headers) && params[:headers].has_key?('Authorization')
        params[:headers] = params[:headers].dup
        params[:headers]['Authorization'] = "REDACTED"
      end

      if params.has_key?(:password)
        params[:password] = "REDACTED"
      end

      if name.include?('request')
        info = "request: " + params[:scheme] + "://" + File.join(params[:host], params[:path])

        if params[:query]
          info << "?"

          if params[:query].is_a?(Hash)
            info << params[:query].to_a.map { |key,value| "#{key}=#{value}" }.join('&')
          else
            info << params[:query]
          end
        end
      else
        response_type = name.split('.').last
        if params[:body]
          info = "#{response_type}: " + params[:body]
        end
      end

      logger.info(info) if info

      yield if block_given?
    end
  end
end

Version data entries

43 entries across 42 versions & 2 rubygems

Version Path
excon-1.2.1 lib/excon/instrumentors/logging_instrumentor.rb
excon-1.2.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-1.1.1 lib/excon/instrumentors/logging_instrumentor.rb
excon-1.1.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-1.0.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.112.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.111.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.110.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.109.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.108.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.107.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.106.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.105.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.104.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.103.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.102.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.101.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.100.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.99.0 lib/excon/instrumentors/logging_instrumentor.rb
excon-0.98.0 lib/excon/instrumentors/logging_instrumentor.rb