Class: U::Log::RackLogger

Inherits:
Rack::CommonLogger
  • Object
show all
Defined in:
lib/u-log/rack_logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, logger) ⇒ RackLogger

Returns a new instance of RackLogger.



11
12
13
14
# File 'lib/u-log/rack_logger.rb', line 11

def initialize(app, logger)
  @app = app
  @logger = logger
end

Class Method Details

.silence_common_logger!Object

In development mode the common logger is always inserted



6
7
8
9
# File 'lib/u-log/rack_logger.rb', line 6

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/u-log/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