Class: Binocs::LogSubscriber

Inherits:
ActiveSupport::LogSubscriber
  • Object
show all
Defined in:
lib/binocs/log_subscriber.rb

Instance Method Summary collapse

Instance Method Details

#halted_callback(event) ⇒ Object



45
46
47
48
49
50
51
52
53
# File 'lib/binocs/log_subscriber.rb', line 45

def halted_callback(event)
  return unless Thread.current[:binocs_logs]

  Thread.current[:binocs_logs] << {
    type: "halted",
    filter: event.payload[:filter],
    timestamp: Time.current.iso8601
  }
end

#process_action(event) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/binocs/log_subscriber.rb', line 5

def process_action(event)
  return unless Thread.current[:binocs_logs]

  payload = event.payload

  Thread.current[:binocs_logs] << {
    type: "controller",
    controller: payload[:controller],
    action: payload[:action],
    format: payload[:format],
    method: payload[:method],
    path: payload[:path],
    status: payload[:status],
    view_runtime: payload[:view_runtime]&.round(2),
    db_runtime: payload[:db_runtime]&.round(2),
    duration: event.duration.round(2),
    timestamp: Time.current.iso8601
  }

  # Capture exception info from the payload if present
  if payload[:exception_object]
    ex = payload[:exception_object]
    Thread.current[:binocs_logs] << {
      type: "exception",
      class: ex.class.name,
      message: ex.message,
      backtrace: ex.backtrace&.first(30),
      cause: exception_cause_chain(ex),
      timestamp: Time.current.iso8601
    }
  elsif payload[:exception]
    Thread.current[:binocs_logs] << {
      type: "exception",
      class: payload[:exception].first,
      message: payload[:exception].second,
      timestamp: Time.current.iso8601
    }
  end
end

#redirect_to(event) ⇒ Object



65
66
67
68
69
70
71
72
73
74
# File 'lib/binocs/log_subscriber.rb', line 65

def redirect_to(event)
  return unless Thread.current[:binocs_logs]

  Thread.current[:binocs_logs] << {
    type: "redirect",
    location: event.payload[:location],
    status: event.payload[:status],
    timestamp: Time.current.iso8601
  }
end

#send_data(event) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/binocs/log_subscriber.rb', line 55

def send_data(event)
  return unless Thread.current[:binocs_logs]

  Thread.current[:binocs_logs] << {
    type: "send_data",
    filename: event.payload[:filename],
    timestamp: Time.current.iso8601
  }
end