Skip to content

Commit

Permalink
Convert to Loggability for logging
Browse files Browse the repository at this point in the history
  • Loading branch information
ged committed May 22, 2012
1 parent f6d7fba commit 10911aa
Show file tree
Hide file tree
Showing 23 changed files with 188 additions and 280 deletions.
4 changes: 3 additions & 1 deletion .rvm.gems
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
hoe-deveiate -v0.0.8
hoe-deveiate -v0.1.1
ruby-ldap -v0.9.12
sequel -v3.31.0
loggability -v0.2.3

2 changes: 1 addition & 1 deletion .tm_properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Settings
projectDirectory = "$CWD"
windowTitle = "${CWD/^.*\///} — «$TM_DISPLAYNAME»"
excludeInFileChooser = "{$exclude,.hg}"
excludeInFileChooser = "{$exclude,.hg,pkg}"

[ source.ruby ]
softTabs = false
Expand Down
6 changes: 2 additions & 4 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ It's inspired by and modeled after {Sequel}[http://sequel.rubyforge.org/], a
kick-ass database library.




== Contributing

You can check out the current development source
Expand All @@ -31,7 +29,7 @@ You can submit bug reports, suggestions, and read more about future plans at

== License

Copyright (c) 2008-2011, Michael Granger and Mahlon E. Smith
Copyright (c) 2008-2012, Michael Granger and Mahlon E. Smith
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -59,7 +57,7 @@ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

This software includes some code from the Sequel database toolkit, used under
This software includes some code from the Sequel database toolkit, used under
the following license terms:

Copyright (c) 2007-2008 Sharon Rosner
Expand Down
76 changes: 23 additions & 53 deletions lib/treequel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'ldap/schema'
require 'ldap/control'

require 'logger'
require 'loggability'
require 'pathname'

require 'uri'
Expand All @@ -24,6 +24,12 @@ class LDAPS < LDAP

# A library for interacting with LDAP modelled after Sequel[http://sequel.rubyforge.org/].
module Treequel
extend Loggability


# Loggability API -- set up a Logger for all Treequel-related logging
log_as :treequel


# Library version
VERSION = '1.8.6'
Expand Down Expand Up @@ -60,58 +66,6 @@ def self::version_string( include_buildnum=false )
end


#
# :section: Logging
#

# Log levels
LOG_LEVELS = {
'debug' => Logger::DEBUG,
'info' => Logger::INFO,
'warn' => Logger::WARN,
'error' => Logger::ERROR,
'fatal' => Logger::FATAL,
}.freeze
LOG_LEVEL_NAMES = LOG_LEVELS.invert.freeze

@default_logger = Logger.new( $stderr )
@default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN

@default_log_formatter = Treequel::LogFormatter.new( @default_logger )
@default_logger.formatter = @default_log_formatter

@logger = @default_logger


class << self
# The log formatter that will be used when the logging subsystem is reset
attr_accessor :default_log_formatter

# The logger that will be used when the logging subsystem is reset
attr_accessor :default_logger

# The logger that's currently in effect
attr_accessor :logger
alias_method :log, :logger
alias_method :log=, :logger=
end


### Reset the global logger object to the default
def self::reset_logger
self.logger = self.default_logger
self.logger.level = Logger::WARN
self.logger.formatter = self.default_log_formatter
end


### Returns +true+ if the global logger has not been set to something other than
### the default one.
def self::using_default_logger?
return self.logger == self.default_logger
end


#
# :section:
#
Expand Down Expand Up @@ -318,6 +272,22 @@ def self::read_opts_from_environment
end


### Reset the logger associated with Treequel. Backward-compatibility method.
def self::reset_logger
Treequel.logger = Treequel.default_logger
Treequel.logger.formatter = nil
Treequel.logger.output_to( $stderr )
Treequel.logger.level = :fatal
end


### Returns +true+ if the current logger for Treequel is the default one.
### Backward-compatibility method.
def self::using_default_logger?
return Loggability[ Treequel ] == Treequel.default_logger
end


# Now load the rest of the library
require 'treequel/exceptions'
require 'treequel/directory'
Expand Down
8 changes: 6 additions & 2 deletions lib/treequel/branch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,19 @@
# for the entries below itself, and how to search for those entries.
class Treequel::Branch
include Comparable,
Treequel::Loggable,
Treequel::Constants,
Treequel::Constants::Patterns,
Treequel::HashUtilities

extend Treequel::Delegation,
extend Loggability,
Treequel::Delegation,
Treequel::AttributeDeclarations


# Loggability API -- Log to the Treequel module's logger
log_to :treequel


# The default width of LDIF output
DEFAULT_LDIF_WIDTH = 70

Expand Down
16 changes: 10 additions & 6 deletions lib/treequel/branchcollection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,33 @@
# A Treequel::BranchCollection is a union of Treequel::Branchset
# objects, suitable for performing operations on multiple branches
# of the directory at once.
#
#
# For example, if you have hosts under ou=Hosts in two different
# subdomains (e.g., acme.com, seattle.acme.com, and newyork.acme.com),
# and you want to search for a host by its CN, you could do so like
# this:
#
#
# # Top-level hosts, and those in the 'seattle' subdomain, but not
# # those in the 'newyork' subdomain:
# west_coast_hosts = dir.ou( :hosts ) + dir.dc( :seattle ).ou( :hosts )
# west_coast_www_hosts = west_coast_hosts.filter( :cn => 'www' )
#
#
# # And one that includes hosts in all three DCs:
# all_hosts = west_coast_hosts + dir.dc( :newyork ).ou( :hosts )
# all_ns_hosts = all_hosts.filter( :cn => 'ns*' )
#
#
# Note that you could accomplish most of what BranchCollection does
# using filters, but some people might find this a bit more readable.
class Treequel::BranchCollection
include Enumerable,
Treequel::Loggable,
Treequel::Constants

extend Treequel::Delegation
extend Loggability,
Treequel::Delegation


# Loggability API -- Log to the Treequel module's logger
log_to :treequel


#################################################################
Expand Down
5 changes: 4 additions & 1 deletion lib/treequel/branchset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,14 @@
# Branchsets are Enumerable objects, so they can be manipulated using any of the
# Enumerable methods, such as map, inject, etc.
class Treequel::Branchset
extend Loggability
include Enumerable,
Treequel::Loggable,
Treequel::Constants,
Treequel::Control

# Loggability API -- Log to the Treequel module's logger
log_to :treequel

# The default scope to use when searching if none is specified
DEFAULT_SCOPE = :subtree
DEFAULT_SCOPE.freeze
Expand Down
12 changes: 8 additions & 4 deletions lib/treequel/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
# The object in Treequel that represents a connection to a directory, the
# binding to that directory, and the base from which all DNs start.
class Treequel::Directory
include Treequel::Loggable,
Treequel::Constants,
include Treequel::Constants,
Treequel::HashUtilities

extend Treequel::Delegation
extend Loggability,
Treequel::Delegation

# Loggability API -- Log to the Treequel module's logger
log_to :treequel


# The default directory options
DEFAULT_OPTIONS = {
Expand Down Expand Up @@ -146,7 +150,7 @@ def initialize( options={} )
end


### Copy constructor -- the duplicate should have a distinct connection, bound user,
### Copy constructor -- the duplicate should have a distinct connection, bound user,
### and should have a distinct copy of the +original+'s registered controls.
def initialize_copy( original )
@conn = nil
Expand Down
Loading

0 comments on commit 10911aa

Please sign in to comment.