Class: Excon::LoggingInstrumentor

Inherits:
Object
  • Object
show all
Defined in:
lib/excon/instrumentors/logging_instrumentor.rb

Class Method Summary collapse

Class Method Details

.instrument(name, params = {}, &block) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/excon/instrumentors/logging_instrumentor.rb', line 19

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

  # 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.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

  self.logger.log(logger.level, info) if info

  yield if block_given?
end

.loggerObject

Returns the Logger object for the LoggingInstrumentor. If one doesn’t already exist, then one will be created using $stderr as the output stream.



9
10
11
# File 'lib/excon/instrumentors/logging_instrumentor.rb', line 9

def self.logger
  @logger ||= Logger.new($stderr)
end

.logger=(logger) ⇒ Object

Sets the logger object for the LoggingInstrumentor.



15
16
17
# File 'lib/excon/instrumentors/logging_instrumentor.rb', line 15

def self.logger=(logger)
  @logger = logger
end