lib/logging.rb in logging-0.6.3 vs lib/logging.rb in logging-0.7.0

- old
+ new

@@ -1,6 +1,6 @@ -# $Id: logging.rb 90 2008-02-08 19:03:48Z tim_pease $ +# $Id: logging.rb 98 2008-02-13 00:40:28Z tim_pease $ # Equivalent to a header guard in C/C++ # Used to prevent the class/module from being loaded more than once unless defined? Logging @@ -10,13 +10,14 @@ # # module Logging # :stopdoc: - VERSION = '0.6.3' + VERSION = '0.7.0' LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR + WIN32 = %r/djgpp|(cyg|ms|bcc)win|mingw/ =~ RUBY_PLATFORM LEVELS = {} LNAMES = {} # :startdoc: class << self @@ -73,11 +74,11 @@ # # See the documentation for the Logging::Layouts::Pattern class for a # full description of the :pattern and :date_pattern formatting strings. # def logger( *args ) - opts = args.pop if Hash === args.last + opts = args.pop if args.last.instance_of?(Hash) opts ||= Hash.new dev = args.shift keep = age = args.shift size = args.shift @@ -98,14 +99,14 @@ l_opts[o] = opts.delete(o) if opts.has_key? o end layout = ::Logging::Layouts::Pattern.new(l_opts) a_opts = Hash.new - a_opts[:size] = size if Fixnum === size - a_opts[:age] = age if String === age - a_opts[:keep] = keep if Fixnum === keep - a_opts[:filename] = dev if String === dev + a_opts[:size] = size if size.instance_of?(Fixnum) + a_opts[:age] = age if age.instance_of?(String) + a_opts[:keep] = keep if keep.instance_of?(Fixnum) + a_opts[:filename] = dev if dev.instance_of?(String) a_opts[:layout] = layout a_opts.merge! opts appender = case dev @@ -114,11 +115,11 @@ else ::Logging::Appenders::IO.new(name, dev, a_opts) end logger = ::Logging::Logger.new(name) - logger.add appender + logger.add_appenders appender logger.additive = false class << logger def close @appenders.each {|a| a.close} @@ -130,11 +131,11 @@ logger end # call-seq: - # Logging.define_levels( levels ) + # Logging.init( levels ) # # Defines the levels available to the loggers. The _levels_ is an array # of strings and symbols. Each element in the array is downcased and # converted to a symbol; these symbols are used to create the logging # methods in the loggers. @@ -152,25 +153,25 @@ # The levels "all" and "off" are reserved and will be ignored if passed # to this method. # # Example: # - # Logging.define_levels :debug, :info, :warn, :error, :fatal + # Logging.init :debug, :info, :warn, :error, :fatal # log = Logging::Logger['my logger'] # log.level = :warn # log.warn 'Danger! Danger! Will Robinson' # log.info 'Just FYI' # => not logged # # or # - # Logging.define_levels %w(DEBUG INFO NOTICE WARNING ERR CRIT ALERT EMERG) + # Logging.init %w(DEBUG INFO NOTICE WARNING ERR CRIT ALERT EMERG) # log = Logging::Logger['syslog'] # log.level = :notice # log.warning 'This is your first warning' # log.info 'Just FYI' # => not logged # - def define_levels( *args ) - return nil if args.empty? + def init( *args ) + args = %w(debug info warn error fatal) if args.empty? args.flatten! levels = ::Logging::LEVELS.clear names = ::Logging::LNAMES.clear