File: log_subscriber.rb

package info (click to toggle)
ruby-activeldap 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 1,588 kB
  • sloc: ruby: 18,143; sh: 12; makefile: 5
file content (54 lines) | stat: -rw-r--r-- 1,100 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
module ActiveLdap
  class LogSubscriber < ActiveSupport::LogSubscriber
    def self.runtime=(value)
      Thread.current["active_ldap_runtime"] = value
    end

    def self.runtime
      Thread.current["active_ldap_runtime"] ||= 0
    end

    def self.reset_runtime
      rt, self.runtime = runtime, 0
      rt
    end

    def initialize
      super
      @odd = false
    end

    def log_info(event)
      self.class.runtime += event.duration
      return unless logger.debug?

      payload = event.payload
      info = payload[:info] || {}
      label = payload[:name]
      label += ": FAILED" if info[:exception]
      name = 'LDAP: %s (%.1fms)' % [label, event.duration]
      inspected_info = info.inspect

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

      debug "  #{name} #{inspected_info}"
    end

    def odd?
      @odd = !@odd
    end

    def logger
      ActiveLdap::Base.logger
    end
  end
end

ActiveLdap::LogSubscriber.attach_to :active_ldap