2 # Rack::CommonLogger forwards every request to an +app+ given, and
3 # logs a line in the Apache common log format to the +logger+, or
4 # rack.errors by default.
7 def initialize(app
, logger
=nil)
20 @status, @header, @body = @app.call(env)
21 [@status, @header, self]
25 @body.close
if @body.respond_to
? :close
28 # By default, log to rack.errors.
30 @env["rack.errors"].write(str
)
31 @env["rack.errors"].flush
43 # Common Log Format: http://httpd.apache.org/docs/1.3/logs.html#common
44 # lilith.local - - [07/Aug/2006 23:58:02] "GET / HTTP/1.1" 500 -
45 # %{%s - %s [%s] "%s %s%s %s" %d %s\n} %
46 @logger << %{%s
- %s
[%s
] "%s %s%s %s" %d
%s
%0.4f
\n} %
48 @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-",
49 @env["REMOTE_USER"] || "-",
50 @now.strftime("%d/%b/%Y %H:%M:%S"),
51 @env["REQUEST_METHOD"],
53 @env["QUERY_STRING"].empty
? ? "" : "?"+@env["QUERY_STRING"],
56 (length
.zero
? ? "-" : length
.to_s
),