Class: Timber::Integrations::ActionView::LogSubscriber::TimberLogSubscriber

Inherits:
ActionView::LogSubscriber
  • Object
show all
Defined in:
lib/timber-rails/action_view/log_subscriber/timber_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.

Instance Method Summary collapse

Instance Method Details

#render_collection(event) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/timber-rails/action_view/log_subscriber/timber_log_subscriber.rb', line 47

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)
      message = "  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: message
      )
    end
  else
    # Older versions of rails delegate this method to #render_template
    render_template(event)
  end
end

#render_partial(event) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/timber-rails/action_view/log_subscriber/timber_log_subscriber.rb', line 29

def render_partial(event)
  return true if silence?

  info do
    full_name = from_rails_root(event.payload[:identifier])
    message = "  Rendered #{full_name}"
    message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
    message << " (#{event.duration.round(1)}ms)"
    message << " #{cache_message(event.payload)}" if event.payload.key?(:cache_hit)

    Events::TemplateRender.new(
      name: full_name,
      duration_ms: event.duration,
      message: 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/timber-rails/action_view/log_subscriber/timber_log_subscriber.rb', line 12

def render_template(event)
  return true if silence?

  info do
    full_name = from_rails_root(event.payload[:identifier])
    message = "  Rendered #{full_name}"
    message << " within #{from_rails_root(event.payload[:layout])}" if event.payload[:layout]
    message << " (#{event.duration.round(1)}ms)"

    Events::TemplateRender.new(
      name: full_name,
      duration_ms: event.duration,
      message: message
    )
  end
end