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

rubocop:disable Style/IfInsideElse



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
# File 'lib/active_fedora/log_subscriber.rb', line 9

def ldp(event)
  return unless logger.debug?

  payload = event.payload

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

  if ActiveSupport.version >= Gem::Version.new('7.1.0')
    if odd?
      name = color(name, CYAN, bold: true)
      id = color(id, nil, bold: true)
    else
      name = color(name, MAGENTA, bold: true)
    end
  else
    if odd?
      name = color(name, CYAN, true)
      id = color(id, nil, true)
    else
      name = color(name, MAGENTA, true)
    end
  end

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

#loggerObject



41
42
43
# File 'lib/active_fedora/log_subscriber.rb', line 41

def logger
  ActiveFedora::Base.logger
end

#odd?Boolean

rubocop:enable Style/IfInsideElse

Returns:

  • (Boolean)


37
38
39
# File 'lib/active_fedora/log_subscriber.rb', line 37

def odd?
  @odd = !@odd
end