aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/railties
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-01-13 00:41:04 +0100
committerJosé Valim <jose.valim@gmail.com>2010-01-13 01:19:23 +0100
commitda5978c22374b8a3b15a421ff4920e0940435253 (patch)
treee9a94394f0ce7455cd0f955ede80e0b5f5f573b0 /actionpack/lib/action_controller/railties
parent8d78a82d797bf8809acb1d2ebb30cf81488ac99c (diff)
downloadrails-da5978c22374b8a3b15a421ff4920e0940435253.tar.gz
rails-da5978c22374b8a3b15a421ff4920e0940435253.tar.bz2
rails-da5978c22374b8a3b15a421ff4920e0940435253.zip
Add subscriber for ActionPack and move all logging inside it.
Diffstat (limited to 'actionpack/lib/action_controller/railties')
-rw-r--r--actionpack/lib/action_controller/railties/subscriber.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/railties/subscriber.rb b/actionpack/lib/action_controller/railties/subscriber.rb
new file mode 100644
index 0000000000..d9d77304ee
--- /dev/null
+++ b/actionpack/lib/action_controller/railties/subscriber.rb
@@ -0,0 +1,62 @@
+module ActionController
+ module Railties
+ class Subscriber < Rails::Subscriber
+ def process_action(event)
+ controller = event.payload[:controller]
+ request = controller.request
+
+ info "\nProcessed #{controller.class.name}##{event.payload[:action]} " \
+ "to #{request.formats} (for #{request.remote_ip} at #{event.time.to_s(:db)}) " \
+ "[#{request.method.to_s.upcase}]"
+
+ params = controller.send(:filter_parameters, request.params)
+ info " Parameters: #{params.inspect}" unless params.empty?
+
+ ActionController::Base.log_process_action(controller)
+
+ message = "Completed in %.0fms" % event.duration
+ message << " | #{controller.response.status}"
+ message << " [#{request.request_uri rescue "unknown"}]\n\n"
+
+ info(message)
+ end
+
+ def send_file(event)
+ message = if event.payload[:x_sendfile]
+ header = ActionController::Streaming::X_SENDFILE_HEADER
+ "Sending #{header} header %s"
+ elsif event.payload[:stream]
+ "Streaming file %s"
+ else
+ "Sending file %s"
+ end
+
+ message << " (%.1fms)"
+ info(message % [event.payload[:path], event.duration])
+ end
+
+ def redirect_to(event)
+ info "Redirected to #{event.payload[:location]} with status #{event.payload[:status]}"
+ end
+
+ def send_data(event)
+ info("Sending data %s (%.1fms)" % [event.payload[:filename], event.duration])
+ end
+
+ %w(write_fragment read_fragment exist_fragment?
+ expire_fragment expire_page write_page).each do |method|
+ class_eval <<-METHOD, __FILE__, __LINE__ + 1
+ def #{method}(event)
+ key_or_path = event.payload[:key] || event.payload[:path]
+ human_name = #{method.to_s.humanize.inspect}
+ info("\#{human_name} \#{key_or_path.inspect} (%.1fms)" % event.duration)
+ end
+ METHOD
+ end
+
+ def logger
+ ActionController::Base.logger
+ end
+ end
+ end
+end \ No newline at end of file