Sha256: c704500811ec4106896e107768c83fee6e74da227556883ef25f171ea59ff765

Contents?: true

Size: 1.02 KB

Versions: 10

Compression:

Stored size: 1.02 KB

Contents

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_or_even = false
    end
    
    def log_info(event)
      self.class.runtime += event.duration
      return unless logger.debug?
  
      payload = event.payload
      name = 'LDAP: %s (%.1fms)' % [payload[:name], event.duration]
      info = payload[:info].inspect
  
      if odd?
        name_color, dump_color = "4;36;1", "0;1"
      else
        name_color, dump_color = "4;35;1", "0"
      end
  
      debug "  \e[#{name_color}m#{name}\e[0m: \e[#{dump_color}m#{info}\e[0m"
    end
    
    def odd?
      @odd_or_even = !@odd_or_even
    end
    
    def logger
      ActiveLdap::Base.logger
    end
  end
end

ActiveLdap::LogSubscriber.attach_to :active_ldap


Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
activeldap-3.2.3 lib/active_ldap/log_subscriber.rb
powerhome-activeldap-3.2.3 lib/active_ldap/log_subscriber.rb
activeldap-4.0.2 lib/active_ldap/log_subscriber.rb
activeldap-4.0.1 lib/active_ldap/log_subscriber.rb
activeldap-4.0.0 lib/active_ldap/log_subscriber.rb
activeldap-3.2.2 lib/active_ldap/log_subscriber.rb
activeldap-3.2.1 lib/active_ldap/log_subscriber.rb
activeldap-3.2.0 lib/active_ldap/log_subscriber.rb
activeldap-3.1.1 lib/active_ldap/log_subscriber.rb
activeldap-3.1.0 lib/active_ldap/log_subscriber.rb