Commits

Michael Granger committed 728b1d3

Update to Loggability 0.3.x.

Comments (0)

Files changed (5)

 hoe-deveiate -v0.1.1
 ruby-ldap -v0.9.12
 sequel -v3.31.0
-loggability -v0.2.3
+loggability -v0.3.0
 
 lib/treequel/schema/objectclass.rb
 lib/treequel/schema/table.rb
 lib/treequel/sequel_integration.rb
-lib/treequel/utils.rb
 spec/data/ad_schema.yml
 spec/data/objectClasses.yml
 spec/data/opends.yml
 	else
 		self.dependency 'ruby-ldap', '~> 0.9'
 	end
+	self.dependency 'loggability', '~> 0.3'
+
 	self.dependency 'rspec', '~> 2.8', :developer
 	self.dependency 'ruby-termios', '~> 0.9', :developer
 	self.dependency 'ruby-terminfo', '~> 0.1', :developer

lib/treequel/utils.rb

-#!/usr/bin/ruby
-
-require 'logger'
-require 'erb'
-require 'bigdecimal'
-require 'date'
-
-require 'treequel'
-require 'treequel/mixins'
-
-
-module Treequel
-
-	# A alternate formatter for Logger instances.
-	class LogFormatter < Logger::Formatter
-
-		# The format to output unless debugging is turned on
-		DEFAULT_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"
-
-		# The format to output if debugging is turned on
-		DEFAULT_DEBUG_FORMAT = "[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"
-
-
-		### Initialize the formatter with a reference to the logger so it can check for log level.
-		def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
-			@logger       = logger
-			@format       = format
-			@debug_format = debug
-
-			super()
-		end
-
-		######
-		public
-		######
-
-		# The Logger object associated with the formatter
-		attr_accessor :logger
-
-		# The logging format string
-		attr_accessor :format
-
-		# The logging format string that's used when outputting in debug mode
-		attr_accessor :debug_format
-
-
-		### Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or
-		### using FORMAT if it's anything less verbose.
-		def call( severity, time, progname, msg )
-			args = [
-				time.strftime( '%Y-%m-%d %H:%M:%S' ),                         # %1$s
-				time.usec,                                                    # %2$d
-				Process.pid,                                                  # %3$d
-				Thread.current == Thread.main ? 'main' : Thread.object_id,    # %4$s
-				severity,                                                     # %5$s
-				progname,                                                     # %6$s
-				msg                                                           # %7$s
-			]
-
-			if @logger.level == Logger::DEBUG
-				return self.debug_format % args
-			else
-				return self.format % args
-			end
-		end
-	end # class LogFormatter
-
-
-	# A ANSI-colorized formatter for Logger instances.
-	class ColorLogFormatter < Logger::Formatter
-		extend Treequel::ANSIColorUtilities
-
-		# Color settings
-		LEVEL_FORMATS = {
-			:debug => colorize( :bold, :black ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s {%6$s} -- %7$s\n"},
-			:info  => colorize( :normal ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
-			:warn  => colorize( :bold, :yellow ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
-			:error => colorize( :red ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
-			:fatal => colorize( :bold, :red, :on_white ) {"[%1$s.%2$06d %3$d/%4$s] %5$5s -- %7$s\n"},
-		}
-
-
-		### Initialize the formatter with a reference to the logger so it can check for log level.
-		def initialize( logger, settings={} ) # :notnew:
-			settings = LEVEL_FORMATS.merge( settings )
-
-			@logger   = logger
-			@settings = settings
-
-			super()
-		end
-
-		######
-		public
-		######
-
-		# The Logger object associated with the formatter
-		attr_accessor :logger
-
-		# The formats, by level
-		attr_accessor :settings
-
-
-		### Log using the format associated with the severity
-		def call( severity, time, progname, msg )
-			args = [
-				time.strftime( '%Y-%m-%d %H:%M:%S' ),                         # %1$s
-				time.usec,                                                    # %2$d
-				Process.pid,                                                  # %3$d
-				Thread.current == Thread.main ? 'main' : Thread.object_id,    # %4$s
-				severity,                                                     # %5$s
-				progname,                                                     # %6$s
-				msg                                                           # %7$s
-			]
-
-			return self.settings[ severity.downcase.to_sym ] % args
-		end
-	end # class LogFormatter
-
-
-	# An alternate formatter for Logger instances that outputs +div+ HTML
-	# fragments.
-	class HtmlLogFormatter < Logger::Formatter
-		include ERB::Util  # for html_escape()
-
-		# The default HTML fragment that'll be used as the template for each log message.
-		HTML_LOG_FORMAT = %q{
-		<div class="log-message %5$s">
-			<span class="log-time">%1$s.%2$06d</span>
-			[
-				<span class="log-pid">%3$d</span>
-				/
-				<span class="log-tid">%4$s</span>
-			]
-			<span class="log-level">%5$s</span>
-			:
-			<span class="log-name">%6$s</span>
-			<span class="log-message-text">%7$s</span>
-		</div>
-		}
-
-		### Override the logging formats with ones that generate HTML fragments
-		def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
-			@logger = logger
-			@format = format
-			super()
-		end
-
-
-		######
-		public
-		######
-
-		# The HTML fragment that will be used as a format() string for the log
-		attr_accessor :format
-
-
-		### Return a log message composed out of the arguments formatted using the
-		### formatter's format string
-		def call( severity, time, progname, msg )
-			args = [
-				time.strftime( '%Y-%m-%d %H:%M:%S' ),                         # %1$s
-				time.usec,                                                    # %2$d
-				Process.pid,                                                  # %3$d
-				Thread.current == Thread.main ? 'main' : Thread.object_id,    # %4$s
-				severity.downcase,                                                     # %5$s
-				progname,                                                     # %6$s
-				html_escape( msg ).gsub(/\n/, '<br />')                       # %7$s
-			]
-
-			return self.format % args
-		end
-
-	end # class HtmlLogFormatter
-
-end # module Treequel
-
-# vim: set nosta noet ts=4 sw=4:
-

spec/lib/helpers.rb

 require 'spec/lib/constants'
 require 'spec/lib/matchers'
 
-### IRb.start_session, courtesy of Joel VanderWerf in [ruby-talk:42437].
-require 'irb'
-require 'irb/completion'
-
-module IRB # :nodoc:
-	def self.start_session( obj )
-		unless @__initialized
-			args = ARGV
-			ARGV.replace( ARGV.dup )
-			IRB.setup( nil )
-			ARGV.replace( args )
-			@__initialized = true
-		end
-
-		workspace = WorkSpace.new( obj )
-		irb = Irb.new( workspace )
-
-		@CONF[:IRB_RC].call( irb.context ) if @CONF[:IRB_RC]
-		@CONF[:MAIN_CONTEXT] = irb.context
-
-		begin
-			prevhandler = Signal.trap( 'INT' ) do
-				irb.signal_handle
-			end
-
-			catch( :IRB_EXIT ) do
-				irb.eval_input
-			end
-		ensure
-			Signal.trap( 'INT', prevhandler )
-		end
-
-	end
-end
+require 'loggability/spechelpers'
 
 
 ### RSpec helper functions.
 module Treequel::SpecHelpers
 	include Treequel::TestConstants
 
-	class ArrayLogger
-		### Create a new ArrayLogger that will append content to +array+.
-		def initialize( array )
-			@array = array
-		end
-
-		### Write the specified +message+ to the array.
-		def write( message )
-			@array << message
-		end
-
-		### No-op -- this is here just so Logger doesn't complain
-		def close; end
-
-	end # class ArrayLogger
-
-
-	unless defined?( LEVEL )
-		LEVEL = {
-			:debug => Logger::DEBUG,
-			:info  => Logger::INFO,
-			:warn  => Logger::WARN,
-			:error => Logger::ERROR,
-			:fatal => Logger::FATAL,
-		  }
-	end
-
 	###############
 	module_function
 	###############
 	end
 
 
-	### Reset the logging subsystem to its default state.
-	def reset_logging
-		Treequel.logger = Treequel.default_logger
-		Loggability.formatter = nil
-		Loggability.output_to( $stderr )
-		Loggability.level = :fatal
-	end
-
-
-	### Alter the output of the default log formatter to be pretty in SpecMate output
-	def setup_logging( level=:fatal )
-
-		# Only do this when executing from a spec in TextMate
-		if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
-			logarray = []
-			Thread.current['logger-output'] = logarray
-			Loggability.output_to( logarray )
-			Loggability.format_as( :html )
-			Loggability.level = :debug
-		else
-			Loggability.level = level
-		end
-	end
-
-
 	### Make a Treequel::Directory that will use the given +conn+ object as its
 	### LDAP connection. Also pre-loads the schema object and fixtures some other
 	### external data.
 
 ### Mock with RSpec
 RSpec.configure do |c|
-	include Treequel::TestConstants
+	include Treequel::TestConstants,
+	        Loggability::SpecHelpers
 
 	c.mock_with :rspec
 
 	c.include( Treequel::TestConstants )
 	c.include( Treequel::SpecHelpers )
 	c.include( Treequel::Matchers )
+	c.include( Loggability::SpecHelpers )
 
 	c.treat_symbols_as_metadata_keys_with_true_values = true