Class: Logtail::Integrations::ActionView::LogSubscriber::LogtailLogSubscriber
- Inherits:
-
ActionView::LogSubscriber
- Object
- ActionView::LogSubscriber
- Logtail::Integrations::ActionView::LogSubscriber::LogtailLogSubscriber
- Defined in:
- lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb
Overview
The log subscriber that replaces the default ‘ActionView::LogSubscriber`. The intent of this subscriber is to, as transparently as possible, properly track events that are being logged here.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.attach_to ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb', line 70 def self.attach_to(*) super if ::Rails::VERSION::MAJOR > 7 || ::Rails::VERSION::MAJOR == 7 && ::Rails::VERSION::MINOR >= 1 # Clean extra listeners subscribed in parent's attach_to method ::ActiveSupport::Notifications.notifier.listeners_for("render_template.action_view") .concat(::ActiveSupport::Notifications.notifier.listeners_for("render_layout.action_view")).flatten .filter { |listener| listener.delegate.class == ::ActionView::LogSubscriber::Start } .each { |listener| ActiveSupport::Notifications.unsubscribe(listener) } end end |
Instance Method Details
#render_collection(event) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb', line 48 def render_collection(event) return true if silence? if respond_to?(:render_count, true) info do identifier = event.payload[:identifier] || "templates" full_name = from_rails_root(identifier) = " Rendered collection of #{full_name}" \ " #{render_count(event.payload)} (#{event.duration.round(1)}ms)" Events::TemplateRender.new( name: full_name, duration_ms: event.duration, message: ) end else # Older versions of rails delegate this method to #render_template render_template(event) end end |
#render_partial(event) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb', line 30 def render_partial(event) return true if silence? info do full_name = from_rails_root(event.payload[:identifier]) = " Rendered #{full_name}" << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout] << " (#{event.duration.round(1)}ms)" << " #{(event.payload)}" if event.payload.key?(:cache_hit) Events::TemplateRender.new( name: full_name, duration_ms: event.duration, message: ) end end |
#render_template(event) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/logtail-rails/action_view/log_subscriber/logtail_log_subscriber.rb', line 12 def render_template(event) return true if silence? info do full_name = from_rails_root(event.payload[:identifier]) = " Rendered #{full_name}" << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout] << " (#{event.duration.round(1)}ms)" Events::TemplateRender.new( name: full_name, duration_ms: event.duration, message: ) end end |