Class: AD::LDAP::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/ad-ldap/logger.rb

Overview

Inspired by github.com/tpett/perry logger

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Logger

Returns a new instance of Logger.



8
9
10
11
# File 'lib/ad-ldap/logger.rb', line 8

def initialize(config)
  self.logger = config.logger
  self.silent = !!config.silent
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/ad-ldap/logger.rb', line 6

def logger
  @logger
end

#silentObject

Returns the value of attribute silent.



6
7
8
# File 'lib/ad-ldap/logger.rb', line 6

def silent
  @silent
end

Instance Method Details

#out(method, args, result, time) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ad-ldap/logger.rb', line 13

def out(method, args, result, time)
  color = "4;32;1"
  name = "%s (%.1fms)" % [ "LDAP", time ]
  message = self.generate_message(method, args)
  output = "  \e[#{color}m#{name}   #{message}\e[0m"
  if self.logger
    self.logger.debug(output)
  elsif !self.silent
    puts output
  end
end