Class: DebugLogging::LogSubscriber

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

Constant Summary collapse

EVENT_FORMAT_STRING =
'%<name>s (%<duration>.3f secs) start=%<time>s end=%<end>s payload=%<payload>s'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.eventObject

Returns the value of attribute event.



8
9
10
# File 'lib/debug_logging/log_subscriber.rb', line 8

def event
  @event
end

Class Method Details

.event_to_format_options(event) ⇒ Hash

Parameters:

  • (ActiveSupport::Notifications::Event)

Returns:

  • (Hash)


25
26
27
28
29
30
31
32
33
# File 'lib/debug_logging/log_subscriber.rb', line 25

def self.event_to_format_options(event)
  {
    name: event.name,
    duration: Rational(event.duration, 1000).to_f,
    time: event.time,
    end: event.end,
    payload: event.payload
  }
end

.log_event(event) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/debug_logging/log_subscriber.rb', line 14

def self.log_event(event)
  @event = event
  if event.payload && event.payload[:exception_object]
    exception = event.payload[:exception_object]
    "#{event.name} [ERROR] : \n#{exception.class} : #{exception.message}\n" + exception.backtrace.join("\n")
  end
  format(EVENT_FORMAT_STRING, event_to_format_options(event))
end