Module | Jpmobile::Rack::CombinedLogger |
In: |
lib/jpmobile/rack/combined_logger.rb
|
Rack::CommonLogger show too few infomation to debugging mobile web application. So you can Rack::Jpmobile::CombinedLogger as alternate. SYNOPSIS
in your_app.up require 'jpmobile/rack' class Rack::CommonLogger include Jpmobile::Rack::CombinedLogger end use Rack::CommonLogger, STDERR # you need not write this when you use rackup on development.
each | -> | orig_each |
XXX: It‘s evil way for replacing Rack::CommonLogger#each.
# File lib/jpmobile/rack/combined_logger.rb, line 17 17: def self.included klass 18: klass.class_eval do 19: alias orig_each each 20: remove_method :each 21: end 22: end
# File lib/jpmobile/rack/combined_logger.rb, line 24 24: def each 25: length = 0 26: @body.each { |part| 27: length += part.size 28: yield part 29: } 30: 31: @now = Time.now 32: 33: # Combined Log Format: http://httpd.apache.org/docs/1.3/logs.html#combined 34: # 127.0.0.1 - frank [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)" 35: # "%h %l %u [%t] \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\"" 36: @logger << %{%s - %s [%s] "%s %s%s %s" %d %s %s "%s" %0.4f\n} % 37: [ 38: @env['HTTP_X_FORWARDED_FOR'] || @env["REMOTE_ADDR"] || "-", 39: @env["REMOTE_USER"] || @env["HTTP_X_DCMGUID"] || @env["HTTP_X_UP_SUBNO"] || @env["HTTP_X_JPHONE_UID"] || @env["HTTP_X_EM_UID"] || "-", 40: @now.strftime("%d/%b/%Y %H:%M:%S"), 41: @env["REQUEST_METHOD"], 42: @env["PATH_INFO"], 43: @env["QUERY_STRING"].empty? ? "" : "?"+@env["QUERY_STRING"], 44: @env["HTTP_VERSION"], 45: @status.to_s[0..3], 46: (length.zero? ? "-" : length.to_s), 47: @env["HTTP_REFERER"] ? %{"#{@env['Referer']}"} : '-', 48: @env["HTTP_USER_AGENT"], 49: @now - @time 50: ] 51: end