Parent

Class Index [+]

Quicksearch

Rack::CommonLogger

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.

Constants

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} %

Public Class Methods

new(app, logger=nil) click to toggle source
    # File lib/rack/commonlogger.rb, line 11
11:     def initialize(app, logger=nil)
12:       @app = app
13:       @logger = logger
14:     end

Public Instance Methods

call(env) click to toggle source
    # File lib/rack/commonlogger.rb, line 16
16:     def call(env)
17:       began_at = Time.now
18:       status, header, body = @app.call(env)
19:       header = Utils::HeaderHash.new(header)
20:       log(env, status, header, began_at)
21:       [status, header, body]
22:     end

Private Instance Methods

extract_content_length(headers) click to toggle source
    # File lib/rack/commonlogger.rb, line 44
44:     def extract_content_length(headers)
45:       value = headers['Content-Length'] or return '-'
46:       value.to_s == '0' ? '-' : value
47:     end
log(env, status, header, began_at) click to toggle source
    # File lib/rack/commonlogger.rb, line 26
26:     def log(env, status, header, began_at)
27:       now = Time.now
28:       length = extract_content_length(header)
29: 
30:       logger = @logger || env['rack.errors']
31:       logger.write FORMAT % [
32:         env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-",
33:         env["REMOTE_USER"] || "-",
34:         now.strftime("%d/%b/%Y %H:%M:%S"),
35:         env["REQUEST_METHOD"],
36:         env["PATH_INFO"],
37:         env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"],
38:         env["HTTP_VERSION"],
39:         status.to_s[0..3],
40:         length,
41:         now - began_at ]
42:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.