aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVipul A M <vipulnsward@gmail.com>2016-02-16 23:26:33 +0530
committerPrem Sichanugrist <s@sikac.hu>2016-02-26 12:08:51 -0500
commitc8915ec335887e07a967f2688d30c800b80ee256 (patch)
tree47041911457445c63bd988623ae8e142bb78cef1
parent364e155f97f3144c06e10f045b7182ed6ee071a1 (diff)
downloadrails-c8915ec335887e07a967f2688d30c800b80ee256.tar.gz
rails-c8915ec335887e07a967f2688d30c800b80ee256.tar.bz2
rails-c8915ec335887e07a967f2688d30c800b80ee256.zip
Added log "Rendering ...", when starting to render a template, to log that we have started to render something, at the very beginning.
This helps to easily identify queries from controller vs views Fixes #23710
-rw-r--r--actionview/lib/action_view/log_subscriber.rb9
-rw-r--r--actionview/lib/action_view/renderer/template_renderer.rb1
-rw-r--r--actionview/test/template/log_subscriber_test.rb9
3 files changed, 16 insertions, 3 deletions
diff --git a/actionview/lib/action_view/log_subscriber.rb b/actionview/lib/action_view/log_subscriber.rb
index aa38db2a3a..2d59033cb3 100644
--- a/actionview/lib/action_view/log_subscriber.rb
+++ b/actionview/lib/action_view/log_subscriber.rb
@@ -30,6 +30,15 @@ module ActionView
end
end
+
+ def start_rendering(event)
+ info do
+ message = "Rendering #{from_rails_root(event.payload[:identifier])}"
+ message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
+ message
+ end
+ end
+
def logger
ActionView::Base.logger
end
diff --git a/actionview/lib/action_view/renderer/template_renderer.rb b/actionview/lib/action_view/renderer/template_renderer.rb
index 9d15bbfca7..fd550d95e1 100644
--- a/actionview/lib/action_view/renderer/template_renderer.rb
+++ b/actionview/lib/action_view/renderer/template_renderer.rb
@@ -50,6 +50,7 @@ module ActionView
view, locals = @view, locals || {}
render_with_layout(layout_name, locals) do |layout|
+ ActiveSupport::Notifications.instrument("start_rendering.action_view", identifier: template.identifier, layout: layout.try(:virtual_path))
instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
template.render(view, locals) { |*name| view._layout_for(*name) }
end
diff --git a/actionview/test/template/log_subscriber_test.rb b/actionview/test/template/log_subscriber_test.rb
index 93a0701dcc..7683444bf0 100644
--- a/actionview/test/template/log_subscriber_test.rb
+++ b/actionview/test/template/log_subscriber_test.rb
@@ -35,7 +35,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
@view.render(:file => "test/hello_world")
wait
- assert_equal 1, @logger.logged(:info).size
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/Rendering test\/hello_world\.erb/, @logger.logged(:info).first)
assert_match(/Rendered test\/hello_world\.erb/, @logger.logged(:info).last)
end
end
@@ -45,7 +46,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
@view.render(:text => "TEXT")
wait
- assert_equal 1, @logger.logged(:info).size
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/Rendering text template/, @logger.logged(:info).first)
assert_match(/Rendered text template/, @logger.logged(:info).last)
end
end
@@ -55,7 +57,8 @@ class AVLogSubscriberTest < ActiveSupport::TestCase
@view.render(:inline => "<%= 'TEXT' %>")
wait
- assert_equal 1, @logger.logged(:info).size
+ assert_equal 2, @logger.logged(:info).size
+ assert_match(/Rendering inline template/, @logger.logged(:info).first)
assert_match(/Rendered inline template/, @logger.logged(:info).last)
end
end