2010-06-24 07:23:43 -04:00
|
|
|
module ActionView
|
|
|
|
# = Action View Log Subscriber
|
|
|
|
#
|
|
|
|
# Provides functionality so that Rails can output logs from Action View.
|
|
|
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
|
|
|
def render_template(event)
|
|
|
|
message = "Rendered #{from_rails_root(event.payload[:identifier])}"
|
|
|
|
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
|
|
|
message << (" (%.1fms)" % event.duration)
|
2010-08-14 01:13:00 -04:00
|
|
|
info(message)
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
alias :render_partial :render_template
|
|
|
|
alias :render_collection :render_template
|
|
|
|
|
2010-06-27 18:46:57 -04:00
|
|
|
# TODO: Ideally, ActionView should have its own logger so it does not depend on AC.logger
|
2010-06-24 07:23:43 -04:00
|
|
|
def logger
|
2010-06-27 18:46:57 -04:00
|
|
|
ActionController::Base.logger if defined?(ActionController::Base)
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def from_rails_root(string)
|
|
|
|
string.sub("#{Rails.root}/", "").sub(/^app\/views\//, "")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-27 18:46:57 -04:00
|
|
|
ActionView::LogSubscriber.attach_to :action_view
|