lib/logging.rb in logging-0.8.0 vs lib/logging.rb in logging-0.9.0
- old
+ new
@@ -1,20 +1,18 @@
-# $Id$
# Equivalent to a header guard in C/C++
# Used to prevent the class/module from being loaded more than once
unless defined? Logging
-# TODO: internal logger for debugging
# TODO: Windows Log Service appender
#
#
module Logging
# :stopdoc:
- VERSION = '0.8.0'
+ VERSION = '0.9.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 = {}
@@ -22,16 +20,24 @@
class << self
# call-seq:
# Logging.configure( filename )
+ # Logging.configure { block }
#
# Configures the Logging framework using the configuration information
# found in the given file. The file extension should be either '.yaml'
# or '.yml' (XML configuration is not yet supported).
#
- def configure( filename, *args )
+ def configure( *args, &block )
+ if block
+ return ::Logging::Config::Configurator.process(&block)
+ end
+
+ filename = args.shift
+ raise ArgumentError, 'a filename was not given' if filename.nil?
+
case File.extname(filename)
when '.yaml', '.yml'
::Logging::Config::YamlConfigurator.load(filename, *args)
else raise ArgumentError, 'unknown configuration file format' end
end
@@ -185,11 +191,11 @@
id += 1
end
end
longest = names.values.inject {|x,y| (x.length > y.length) ? x : y}
- module_eval "MAX_LEVEL_LENGTH = #{longest.length}"
+ module_eval "MAX_LEVEL_LENGTH = #{longest.length}", __FILE__, __LINE__
levels.keys
end
# call-seq:
@@ -212,11 +218,11 @@
unless [:string, :inspect, :yaml].include? f
raise ArgumentError, "unknown object format '#{f}'"
end
- module_eval "OBJ_FORMAT = :#{f}"
+ module_eval "OBJ_FORMAT = :#{f}", __FILE__, __LINE__
end
# Returns the version string for the library.
#
def version
@@ -226,18 +232,18 @@
# Returns the library path for the module. If any arguments are given,
# they will be joined to the end of the libray path using
# <tt>File.join</tt>.
#
def libpath( *args )
- args.empty? ? LIBPATH : ::File.join(LIBPATH, *args)
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
end
# Returns the lpath for the module. If any arguments are given,
# they will be joined to the end of the path using
# <tt>File.join</tt>.
#
def path( *args )
- args.empty? ? PATH : ::File.join(PATH, *args)
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
end
# Utility method used to rquire all files ending in .rb that lie in the
# directory below this file that has the same name as the filename passed
# in. Optionally, a specific _directory_ name can be passed in such that