lib/logging.rb in logging-0.6.2 vs lib/logging.rb in logging-0.6.3
- old
+ new
@@ -1,55 +1,39 @@
-# $Id: logging.rb 85 2008-02-06 17:59:00Z tim_pease $
+# $Id: logging.rb 90 2008-02-08 19:03:48Z tim_pease $
-require 'logging/utils'
-require 'logging/log_event'
-require 'logging/logger'
-require 'logging/root_logger'
-require 'logging/repository'
-require 'logging/appender'
-require 'logging/layout'
+# Equivalent to a header guard in C/C++
+# Used to prevent the class/module from being loaded more than once
+unless defined? Logging
-# require all appenders
-require 'logging/appenders/static_appender'
-require 'logging/appenders/io'
-require 'logging/appenders/console'
-require 'logging/appenders/email'
-require 'logging/appenders/file'
-require 'logging/appenders/growl'
-require 'logging/appenders/rolling_file'
-require 'logging/appenders/syslog'
+# TODO: internal logger for debugging
+# TODO: Windows Log Service appender
-# require all layouts
-require 'logging/layouts/basic'
-require 'logging/layouts/pattern'
-
-# require all configurators
-require 'logging/config/yaml_configurator'
-
-
#
#
module Logging
- VERSION = '0.6.2' # :nodoc:
+ # :stopdoc:
+ VERSION = '0.6.3'
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
+ LEVELS = {}
+ LNAMES = {}
+ # :startdoc:
- LEVELS = {} # :nodoc:
- LNAMES = {} # :nodoc:
-
class << self
# call-seq:
# Logging.configure( filename )
#
# 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 )
+ def configure( filename, *args )
case File.extname(filename)
when '.yaml', '.yml'
- ::Logging::Config::YamlConfigurator.load(filename)
+ ::Logging::Config::YamlConfigurator.load(filename, *args)
else raise ArgumentError, 'unknown configuration file format' end
end
# call-seq:
# Logging.logger( device, age = 7, size = 1048576 )
@@ -230,12 +214,46 @@
end
module_eval "OBJ_FORMAT = :#{f}"
end
- # :stopdoc:
+ # Returns the version string for the library.
+ #
+ def version
+ VERSION
+ end
+ # 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)
+ 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)
+ 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
+ # the _filename_ does not have to be equivalent to the directory.
+ #
+ def require_all_libs_relative_to( fname, dir = nil )
+ dir ||= ::File.basename(fname, '.*')
+ search_me = ::File.expand_path(
+ ::File.join(::File.dirname(fname), dir, '*.rb'))
+
+ Dir.glob(search_me).sort.each {|rb| require rb}
+ end
+
+ # :stopdoc:
# Convert the given level into a connaconical form - a lowercase string.
def levelify( level )
case level
when String; level.downcase
when Symbol; level.to_s.downcase
@@ -250,19 +268,23 @@
when 'off'; LEVELS.length
else begin; Integer(l); rescue ArgumentError; LEVELS[l] end end
end
# :startdoc:
end
-
end # module Logging
+Logging.require_all_libs_relative_to(__FILE__)
+Logging.require_all_libs_relative_to(__FILE__, 'logging/config')
+
# This exit handler will close all the appenders that exist in the system.
# This is needed for closing IO streams and connections to the syslog server
# or e-mail servers, etc.
#
at_exit {
Logging::Appender.instance_variable_get(:@appenders).values.each do |ap|
ap.close
end
}
+
+end # unless defined?
# EOF