Object
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.
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} %
# File lib/rack/commonlogger.rb, line 18 18: def call(env) 19: began_at = Time.now 20: status, header, body = @app.call(env) 21: header = Utils::HeaderHash.new(header) 22: body = BodyProxy.new(body) { log(env, status, header, began_at) } 23: [status, header, body] 24: end
# File lib/rack/commonlogger.rb, line 46 46: def extract_content_length(headers) 47: value = headers['Content-Length'] or return '-' 48: value.to_s == '0' ? '-' : value 49: end
# File lib/rack/commonlogger.rb, line 28 28: def log(env, status, header, began_at) 29: now = Time.now 30: length = extract_content_length(header) 31: 32: logger = @logger || env['rack.errors'] 33: logger.write FORMAT % [ 34: env['HTTP_X_FORWARDED_FOR'] || env["REMOTE_ADDR"] || "-", 35: env["REMOTE_USER"] || "-", 36: now.strftime("%d/%b/%Y %H:%M:%S"), 37: env["REQUEST_METHOD"], 38: env["PATH_INFO"], 39: env["QUERY_STRING"].empty? ? "" : "?"+env["QUERY_STRING"], 40: env["HTTP_VERSION"], 41: status.to_s[0..3], 42: length, 43: now - began_at ] 44: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.