Class: Admincredible::Middleware::Response::Logger

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

Overview

So you’re sitting there and you’re staring off into the abyss of your terminal, the solarized green color scheme begins to sink into your retinas and the anger begins to build. This class prevents hulk moments from occurring and automagically logs requests in when enable via config.

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = nil) ⇒ Logger

Returns a new instance of Logger.



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

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

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
# File 'lib/admincredible/middleware/logger.rb', line 20

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

#on_complete(env) ⇒ Object



26
27
28
29
# File 'lib/admincredible/middleware/logger.rb', line 26

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