Class: Objectify::Rails::LogSubscriber

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

Instance Method Summary collapse

Instance Method Details

#duration(event) ⇒ Object



50
51
52
# File 'lib/objectify/rails/log_subscriber.rb', line 50

def duration(event)
  "#{"(%.1fms)" % event.duration}"
end

#executor(event) ⇒ Object



33
34
35
36
37
38
# File 'lib/objectify/rails/log_subscriber.rb', line 33

def executor(event)
  if logger.debug?
    type = event.payload[:type].to_s.capitalize
    logger.debug("    [#{type}] Executed #{event.payload[:name]} " + duration(event))
  end
end

#executor_start(event) ⇒ Object



26
27
28
29
30
31
# File 'lib/objectify/rails/log_subscriber.rb', line 26

def executor_start(event)
  if logger.debug?
    type = event.payload[:type].to_s.capitalize
    logger.debug("    [#{type}] Executing #{event.payload[:name]} " + duration(event))
  end
end

#inject(event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/objectify/rails/log_subscriber.rb', line 10

def inject(event)
  if logger.debug?
    object     = event.payload[:object]
    method     = event.payload[:method]
    parameters = event.payload[:parameters].map do |req, param|
      param if req == :req
    end.compact
    arguments  = event.payload[:arguments].map(&:class).inspect[1..-2]

    message = "      [Injector] Invoking #{object}.#{method}(#{arguments}). "
    message << duration(event)

    logger.debug(message)
  end
end

#loggerObject



46
47
48
# File 'lib/objectify/rails/log_subscriber.rb', line 46

def logger
  ::Rails.logger
end

#policy_chain_halted(event) ⇒ Object



40
41
42
43
44
# File 'lib/objectify/rails/log_subscriber.rb', line 40

def policy_chain_halted(event)
  if logger.debug?
    logger.debug("    [Policy] Chain halted at #{event.payload[:policy]}. Responding with #{event.payload[:responder]}." + duration(event))
  end
end

#start_processing(event) ⇒ Object



6
7
8
# File 'lib/objectify/rails/log_subscriber.rb', line 6

def start_processing(event)
  logger.debug("    [Objectify] Started #{event.payload[:route]}")
end