lib/logging.rb in logging-0.9.8 vs lib/logging.rb in logging-1.0.0
- old
+ new
@@ -1,21 +1,38 @@
# Equivalent to a header guard in C/C++
# Used to prevent the class/module from being loaded more than once
unless defined? Logging
+require 'yaml'
+require 'stringio'
require 'thread'
+
+begin
+ require 'lockfile'
+rescue LoadError
+ retry if require 'rubygems'
+ raise
+end
+
+begin
+ require 'syslog'
+ HAVE_SYSLOG = true
+rescue LoadError
+ HAVE_SYSLOG = false
+end
+
begin require 'fastthread'; rescue LoadError; end
# TODO: Windows Log Service appender
#
#
module Logging
# :stopdoc:
- VERSION = '0.9.8'
+ VERSION = '1.0.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 = []
@@ -83,10 +100,12 @@
#
# See the documentation for the Logging::Layouts::Pattern class for a
# full description of the :pattern and :date_pattern formatting strings.
#
def logger( *args )
+ return ::Logging::Logger if args.empty?
+
opts = args.pop if args.last.instance_of?(Hash)
opts ||= Hash.new
dev = args.shift
keep = age = args.shift
@@ -139,10 +158,22 @@
end
logger
end
+ # Access to the layouts.
+ #
+ def layouts
+ ::Logging::Layouts
+ end
+
+ # Access to the appenders.
+ #
+ def appenders
+ ::Logging::Appenders
+ end
+
# call-seq:
# 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
@@ -180,12 +211,12 @@
#
def init( *args )
args = %w(debug info warn error fatal) if args.empty?
args.flatten!
- levels = ::Logging::LEVELS.clear
- names = ::Logging::LNAMES.clear
+ levels = LEVELS.clear
+ names = LNAMES.clear
id = 0
args.each do |lvl|
lvl = levelify lvl
unless levels.has_key?(lvl) or lvl == 'all' or lvl == 'off'
@@ -272,23 +303,10 @@
#
def 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
- # 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
-
# call-seq:
# show_configuration( io = STDOUT, logger = 'root' )
#
# This method is used to show the configuration of the logging
# framework. The information is written to the given _io_ stream
@@ -384,21 +402,32 @@
end
# :startdoc:
end
end # module Logging
-Logging.require_all_libs_relative_to(__FILE__)
-Logging.require_all_libs_relative_to(__FILE__, 'logging/config')
+require Logging.libpath(%w[logging utils])
+require Logging.libpath(%w[logging appender])
+require Logging.libpath(%w[logging layout])
+require Logging.libpath(%w[logging log_event])
+require Logging.libpath(%w[logging logger])
+require Logging.libpath(%w[logging repository])
+require Logging.libpath(%w[logging root_logger])
+require Logging.libpath(%w[logging stats])
+require Logging.libpath(%w[logging appenders])
+require Logging.libpath(%w[logging layouts])
+
+require Logging.libpath(%w[logging config configurator])
+require Logging.libpath(%w[logging config yaml_configurator])
+
+
# 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.log_internal {'at_exit hook called - closing all appenders'}
- Logging::Appender.instance_variable_get(:@appenders).values.each do |ap|
- ap.close
- end
+ Logging::Appenders.each {|appender| appender.close}
}
end # unless defined?
# EOF