Class: Rack::CommonLogger

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/commonlogger.rb

Overview

Rack::CommonLogger forwards every request to an app given, and logs a line in the Apache common log format to the logger, or rack.errors by default.

Constant Summary collapse

FORMAT =

Common Log Format: httpd.apache.org/docs/1.3/logs.html#common lilith.local - - [07/Aug/2006 23:58:02] “GET / HTTP/1.1” 500 -

%{%s - %s [%s] "%s %s%s %s" %d %s\n} %
%{%s - %s [%s] "%s %s%s %s" %d %s %0.4f\n}

Instance Method Summary collapse

Constructor Details

#initialize(app, logger = nil) ⇒ CommonLogger

Returns a new instance of CommonLogger.



11
12
13
14
# File 'lib/rack/commonlogger.rb', line 11

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

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
# File 'lib/rack/commonlogger.rb', line 16

def call(env)
  began_at = Time.now
  status, header, body = @app.call(env)
  log(env, status, header, began_at)
  [status, header, body]
end