Class: Force::Middleware::Logger

Inherits:
Faraday::Response::Middleware
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/force/middleware/logger.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, logger, options) ⇒ Logger

Returns a new instance of Logger.


7
8
9
10
11
12
13
14
# File 'lib/force/middleware/logger.rb', line 7

def initialize(app, logger, options)
  super(app)
  @options = options
  @logger = logger || begin
    require 'logger'
    ::Logger.new(STDOUT)
  end
end

Instance Method Details

#call(env) ⇒ Object


18
19
20
21
22
23
24
25
26
# File 'lib/force/middleware/logger.rb', line 18

def call(env)
  debug('request') do
    dump :url => env[:url].to_s,
      :method => env[:method],
      :headers => env[:request_headers],
      :body => env[:body]
  end
  super
end

#dump(hash) ⇒ Object


36
37
38
# File 'lib/force/middleware/logger.rb', line 36

def dump(hash)
  "\n" + hash.map { |k, v| "  #{k}: #{v.inspect}" }.join("\n")
end

#on_complete(env) ⇒ Object


28
29
30
31
32
33
34
# File 'lib/force/middleware/logger.rb', line 28

def on_complete(env)
  debug('response') do
    dump :status => env[:status].to_s,
      :headers => env[:response_headers],
      :body => env[:body]
  end
end