lib/logging.rb in TwP-logging-1.0.0 vs lib/logging.rb in TwP-logging-1.1.0
- old
+ new
@@ -28,11 +28,11 @@
#
#
module Logging
# :stopdoc:
- VERSION = '1.0.0'
+ VERSION = '1.1.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 = []
@@ -168,9 +168,70 @@
# Access to the appenders.
#
def appenders
::Logging::Appenders
+ end
+
+ # call-seq:
+ # Logging.consolidate( 'First::Name', 'Second::Name', ... )
+ #
+ # Consolidate all loggers under the given namespace. All child loggers
+ # in the namespace will use the "consolidated" namespace logger instead
+ # of creating a new logger for each class or module.
+ #
+ # If the "root" logger name is passed to this method then all loggers
+ # will consolidate to the root logger. In other words, only the root
+ # logger will be created, and it will be used by all classes and moduels
+ # in the applicaiton.
+ #
+ # ==== Example
+ #
+ # Logging.consolidate( 'Foo' )
+ #
+ # foo = Logging.logger['Foo']
+ # bar = Logging.logger['Foo::Bar']
+ # baz = Logging.logger['Baz']
+ #
+ # foo.object_id == bar.object_id #=> true
+ # foo.object_id == baz.object_id #=> false
+ #
+ def consolidate( *args )
+ ::Logging::Repository.instance.add_master(*args)
+ end
+
+ # call-seq:
+ # include Logging.globally
+ # include Logging.globally( :logger )
+ #
+ # Add a "logger" method to the including context. If included from
+ # Object or Kernel, the logger method will be available to all objects.
+ #
+ # Optionally, a method name can be given and that will be used to
+ # provided access to the logger:
+ #
+ # include Logging.globally( :log )
+ # log.info "Just using a shorter method name"
+ #
+ # If you prefer to use the shorter "log" to access the logger.
+ #
+ # ==== Example
+ #
+ # include Logging.globally
+ #
+ # class Foo
+ # logger.debug "Loading the Foo class"
+ # def initialize
+ # logger.info "Creating some new foo"
+ # end
+ # end
+ #
+ # logger.fatal "End of example"
+ #
+ def globally( name = :logger )
+ Module.new {
+ eval "def #{name}() @_logging_logger ||= ::Logging::Logger[self] end"
+ }
end
# call-seq:
# Logging.init( levels )
#