Class: Lines::RackLogger

Inherits:
Rack::CommonLogger
  • Object
show all
Defined in:
lib/lines/rack_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RackLogger

Returns a new instance of RackLogger.



12
13
14
# File 'lib/lines/rack_logger.rb', line 12

def initialize(app)
  @app = app
end

Class Method Details

.silence_common_logger!Object

In development mode the common logger is always inserted



7
8
9
10
# File 'lib/lines/rack_logger.rb', line 7

def self.silence_common_logger!
  Rack::CommonLogger.module_eval('def call(env); @app.call(env); end')
  self
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/lines/rack_logger.rb', line 16

def call(env)
  began_at = Time.now
  status, header, body = @app.call(env)
  header = Rack::Utils::HeaderHash.new(header)
  body = Rack::BodyProxy.new(body) { log(env, status, header, began_at) }
  [status, header, body]
end