Class: ActiveFedora::LogSubscriber

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

Instance Method Summary collapse

Constructor Details

#initializeLogSubscriber

Returns a new instance of LogSubscriber.



3
4
5
6
# File 'lib/active_fedora/log_subscriber.rb', line 3

def initialize
  super
  @odd = false
end

Instance Method Details

#ldp(event) ⇒ Object



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

def ldp(event)
  return unless logger.debug?

  payload = event.payload

  name = "#{payload[:name]} (#{event.duration.round(1)}ms)"
  id = payload[:id] || "[no id]"

  if odd?
    name = color(name, CYAN, true)
    id = color(id, nil, true)
  else
    name = color(name, MAGENTA, true)
  end

  debug "  #{name} #{id} Service: #{payload[:ldp_service]}"
end

#loggerObject



30
31
32
# File 'lib/active_fedora/log_subscriber.rb', line 30

def logger
  ActiveFedora::Base.logger
end

#odd?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/active_fedora/log_subscriber.rb', line 26

def odd?
  @odd = !@odd
end