Class: ZendeskAPI::Middleware::Response::Logger

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zendesk_api/middleware/response/logger.rb

Overview

Faraday middleware to handle logging

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = nil) ⇒ Logger


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

def initialize(app, logger = nil)
  super(app)

  @logger = logger || begin
    require 'logger'
    ::Logger.new(STDOUT)
  end
end

Instance Method Details

#call(env) ⇒ Object


16
17
18
19
20
21
22
23
24
# File 'lib/zendesk_api/middleware/response/logger.rb', line 16

def call(env)
  @logger.info "#{env[:method]} #{env[:url].to_s}"
  @logger.debug dump_debug(env, :request_headers)

  @app.call(env).on_complete do |env|
    @logger.info("Status #{env[:status].to_s}")
    @logger.debug dump_debug(env, :response_headers)
  end
end