Skip to content

Commit 9c58a54

Browse files
jhawthornHParker
andcommitted
Split actionview log subscriber Start events
Previously one subscriber was used for both the "Rendering" (before) and "Rendered" (after) events. With the previous change to AS::Subscriber these need to be split. Co-authored-by: Adam Hess <[email protected]>
1 parent 9f0b8eb commit 9c58a54

File tree

1 file changed

+44
-31
lines changed

1 file changed

+44
-31
lines changed

actionview/lib/action_view/log_subscriber.rb

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,58 @@ def render_collection(event)
5050
end
5151
end
5252

53-
def start(name, id, payload)
54-
log_rendering_start(payload, name)
53+
module Utils # :nodoc:
54+
def logger
55+
ActionView::Base.logger
56+
end
5557

56-
super
57-
end
58+
private
59+
def from_rails_root(string)
60+
string = string.sub(rails_root, "")
61+
string.sub!(VIEWS_PATTERN, "")
62+
string
63+
end
5864

59-
def logger
60-
ActionView::Base.logger
65+
def rails_root # :doc:
66+
@root ||= "#{Rails.root}/"
67+
end
6168
end
6269

63-
private
64-
EMPTY = ""
65-
def from_rails_root(string) # :doc:
66-
string = string.sub(rails_root, EMPTY)
67-
string.sub!(VIEWS_PATTERN, EMPTY)
68-
string
70+
include Utils
71+
72+
class Start # :nodoc:
73+
include Utils
74+
75+
def start(name, id, payload)
76+
return unless logger
77+
logger.debug do
78+
qualifier =
79+
if name == "render_template.action_view"
80+
""
81+
elsif name == "render_layout.action_view"
82+
"layout "
83+
end
84+
85+
return unless qualifier
86+
87+
message = +" Rendering #{qualifier}#{from_rails_root(payload[:identifier])}"
88+
message << " within #{from_rails_root(payload[:layout])}" if payload[:layout]
89+
message
90+
end
91+
end
92+
93+
def finish(name, id, payload)
94+
end
6995
end
7096

71-
def rails_root # :doc:
72-
@root ||= "#{Rails.root}/"
97+
def self.attach_to(*)
98+
ActiveSupport::Notifications.subscribe("render_template.action_view", ActionView::LogSubscriber::Start.new)
99+
ActiveSupport::Notifications.subscribe("render_layout.action_view", ActionView::LogSubscriber::Start.new)
100+
101+
super
73102
end
74103

104+
private
75105
def render_count(payload) # :doc:
76106
if payload[:cache_hits]
77107
"[#{payload[:cache_hits]} / #{payload[:count]} cache hits]"
@@ -88,23 +118,6 @@ def cache_message(payload) # :doc:
88118
"[cache miss]"
89119
end
90120
end
91-
92-
def log_rendering_start(payload, name)
93-
debug do
94-
qualifier =
95-
if name == "render_template.action_view"
96-
""
97-
elsif name == "render_layout.action_view"
98-
"layout "
99-
end
100-
101-
return unless qualifier
102-
103-
message = +" Rendering #{qualifier}#{from_rails_root(payload[:identifier])}"
104-
message << " within #{from_rails_root(payload[:layout])}" if payload[:layout]
105-
message
106-
end
107-
end
108121
end
109122
end
110123

0 commit comments

Comments
 (0)