lib/rackamole/mole.rb in rackamole-0.0.2 vs lib/rackamole/mole.rb in rackamole-0.0.3
- old
+ new
@@ -71,20 +71,24 @@
# Extract interesting information from the request
def mole_info( env, elapsed, status, headers, body )
request = Rack::Request.new( env )
info = OrderedHash.new
-
+
+ # dump( env )
+
return info unless mole_request?( request )
session = env['rack.session']
route = get_route( request )
ip, browser = identify( env )
user_id = nil
user_name = nil
+ # BOZO !! This could be slow if have to query db to get user name...
+ # Preferred store username in session and give at key
if session and @user_key
if @user_key.instance_of? Symbol
user_name = session[@user_key]
elsif @user_key.instance_of? Hash
user_id = session[ @user_key[:session_key] ]
@@ -98,10 +102,12 @@
info[:environment] = @environment if @environment
info[:user_id] = user_id if user_id
info[:user_name] = user_name || "Unknown"
info[:ip] = ip
info[:browser] = browser
+ info[:host] = env['SERVER_NAME']
+ info[:software] = env['SERVER_SOFTWARE']
info[:request_time] = elapsed if elapsed
info[:perf_issue] = (elapsed and elapsed > @perf_threshold)
info[:url] = request.url
info[:method] = env['REQUEST_METHOD']
info[:path] = request.path
@@ -149,8 +155,23 @@
# Fetch route info if any...
def get_route( request )
return nil unless defined?( RAILS_ENV )
::ActionController::Routing::Routes.recognize_path( request.path, {:method => request.request_method.downcase.to_sym } )
+ end
+
+ # Dump env to stdout
+ def dump( env, level=0 )
+ env.keys.sort{ |a,b| a.to_s <=> b.to_s }.each do |k|
+ value = env[k]
+ if value.respond_to?(:each_pair)
+ puts "%s %-#{40-level}s" % [' '*level,k]
+ dump( env[k], level+1 )
+ elsif value.instance_of?(::ActionController::Request) or value.instance_of?(::ActionController::Response)
+ puts "%s %-#{40-level}s %s" % [ ' '*level, k, value.class ]
+ else
+ puts "%s %-#{40-level}s %s" % [ ' '*level, k, value.inspect ]
+ end
+ end
end
end
end
\ No newline at end of file