Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added log "Rendering ...", when starting to render a template #23717

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions actionview/lib/action_view/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ def render_template(event)
alias :render_partial :render_template
alias :render_collection :render_template


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
Expand Down
1 change: 1 addition & 0 deletions actionview/lib/action_view/renderer/template_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def render_template(template, layout_name = nil, locals = nil) #:nodoc:
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))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the idea of publishing a new instrumentation when we already know where a instrumentation starts. Our Subscribers are evented, it works with start and finish events. We only need to expose an API for this in the subscribers. I'll work on that.

instrument(:template, :identifier => template.identifier, :layout => layout.try(:virtual_path)) do
template.render(view, locals) { |*name| view._layout_for(*name) }
end
Expand Down
9 changes: 6 additions & 3 deletions actionview/test/template/log_subscriber_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def test_render_file_template
@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
Expand All @@ -45,7 +46,8 @@ def test_render_text_template
@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
Expand All @@ -55,7 +57,8 @@ def test_render_inline_template
@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
Expand Down