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
|
2012-09-19 19:00:28 -04:00
|
|
|
VIEWS_PATTERN = /^app\/views\//.freeze
|
|
|
|
|
2010-06-24 07:23:43 -04:00
|
|
|
def render_template(event)
|
2012-09-19 19:00:28 -04:00
|
|
|
return unless logger.info?
|
2011-06-24 15:01:57 -04:00
|
|
|
message = " Rendered #{from_rails_root(event.payload[:identifier])}"
|
2010-06-24 07:23:43 -04:00
|
|
|
message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
|
2012-09-19 19:00:28 -04:00
|
|
|
message << " (#{event.duration.round(1)}ms)"
|
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
|
|
|
|
|
|
|
|
def logger
|
2012-01-18 12:05:36 -05:00
|
|
|
ActionView::Base.logger
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def from_rails_root(string)
|
2012-09-19 19:00:28 -04:00
|
|
|
string.sub("#{Rails.root}/", "").sub(VIEWS_PATTERN, "")
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-06-27 18:46:57 -04:00
|
|
|
ActionView::LogSubscriber.attach_to :action_view
|