Class: DebugLogging::LogSubscriber

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

Constant Summary collapse

EXCLUDE_FROM_PAYLOAD =
i[debug_args config_proxy].freeze
EVENT_FORMAT_STRING =
'%<name>s (%<duration>.3f secs) start=%<time>s end=%<end>s args=%<args>s payload=%<payload>s'

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from ArgumentPrinter

debug_benchmark_to_s, debug_event_name_to_s, debug_invocation_id_to_s, debug_invocation_to_s, debug_payload_to_s, debug_signature_to_s

Class Attribute Details

.eventObject

Returns the value of attribute event.



11
12
13
# File 'lib/debug_logging/log_subscriber.rb', line 11

def event
  @event
end

Class Method Details

.event_to_format_options(event) ⇒ Hash

Parameters:

  • (ActiveSupport::Notifications::Event)

Returns:

  • (Hash)


29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/debug_logging/log_subscriber.rb', line 29

def self.event_to_format_options(event)
  args = event.payload[:debug_args]
  config_proxy = event.payload[:config_proxy]
  payload = event.payload.reject { |k, _| EXCLUDE_FROM_PAYLOAD.include?(k) }
  {
    name: event.name,
    duration: Rational(event.duration, 1000).to_f,
    time: event.time,
    end: event.end,
    args: debug_signature_to_s(args: args, config_proxy: config_proxy),
    payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy)
  }
end

.log_event(event) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/debug_logging/log_subscriber.rb', line 17

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")
  else
    format(EVENT_FORMAT_STRING, event_to_format_options(event))
  end
end