Class: TrackerApi::Logger

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

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = nil) ⇒ Logger

Returns a new instance of Logger.



5
6
7
8
# File 'lib/tracker_api/logger.rb', line 5

def initialize(app, logger = nil)
  super(app)
  @logger = logger || ::Logger.new(STDOUT)
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
# File 'lib/tracker_api/logger.rb', line 12

def call(env)
  info("#{env[:method]} => #{env[:url].to_s}")
  debug('request') { dump_headers env[:request_headers] }
  debug('request.body') { env[:body] }
  super
end

#on_complete(env) ⇒ Object



19
20
21
22
23
# File 'lib/tracker_api/logger.rb', line 19

def on_complete(env)
  info("#{env[:status]} <= #{env[:url].to_s}")
  debug('response') { dump_headers env[:response_headers] }
  debug('response.body') { env[:body] }
end