lib/logging.rb in logging-1.8.2 vs lib/logging.rb in logging-2.0.0

- old
+ new

@@ -1,19 +1,19 @@ - -# Equivalent to a header guard in C/C++ -# Used to prevent the class/module from being loaded more than once -unless defined? Logging - require File.expand_path('../logging/utils', __FILE__) require 'yaml' require 'stringio' require 'fileutils' require 'little-plugger' require 'multi_json' -HAVE_SYSLOG = require? 'syslog' +begin + require 'syslog' + HAVE_SYSLOG = true +rescue LoadError + HAVE_SYSLOG = false +end # # module Logging extend LittlePlugger @@ -27,32 +27,10 @@ # :startdoc: 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( *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 - - # call-seq: # Logging.logger( device, age = 7, size = 1048576 ) # Logging.logger( device, age = 'weekly' ) # # This convenience method returns a Logger instance configured to behave # similarly to a core Ruby Logger instance. @@ -184,38 +162,10 @@ ::Logging::Appenders.each {|appender| appender.reopen} self 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 modules - # in the application. - # - # ==== 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) - self - 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. @@ -359,16 +309,10 @@ else raise ArgumentError, "backtrace must be true or false" end end - # Returns the version string for the library. - # - def version - @version ||= File.read(path('version.txt')).strip - end - # Returns the library path for the module. If any arguments are given, # they will be joined to the end of the library path using # <tt>File.join</tt>. # def libpath( *args, &block ) @@ -432,15 +376,15 @@ # 3) additivity - a "+A" shows the logger is additive, and log events # will be passed up to the parent logger; "-A" shows # that the logger will *not* pass log events up to the # parent logger # - # 4) trace - a "+T" shows that the logger will include trace - # information in generated log events (this includes - # filename and line number of the log message; "-T" - # shows that the logger does not include trace - # information in the log events) + # 4) tracing - a "+T" shows that the logger will include caller + # tracing information in generated log events (this + # includes filename and line number of the log + # message); "-T" shows that the logger does not include + # caller tracing information in the log events # # If a logger has appenders then they are listed, one per line, # immediately below the logger. Appender lines are pre-pended with a # single dash: # @@ -461,19 +405,19 @@ # to false. It uses its own appender to send messages to stderr. # def show_configuration( io = STDOUT, logger = 'root', indent = 0 ) logger = ::Logging::Logger[logger] unless ::Logging::Logger === logger - logger._dump_configuration(io, indent) + io << logger._dump_configuration(indent) indent += 2 children = ::Logging::Repository.instance.children(logger.name) children.sort {|a,b| a.name <=> b.name}.each do |child| ::Logging.show_configuration(io, child, indent) end - self + io end # :stopdoc: # Convert the given level into a canonical form - a lowercase string. def levelify( level ) @@ -495,10 +439,18 @@ # Internal logging method for use by the framework. def log_internal( level = 1, &block ) ::Logging::Logger[::Logging].__send__(levelify(LNAMES[level]), &block) end + # Internal logging method for handling exceptions. If the + # `Thread#abort_on_exception` flag is set then the + # exception will be raised again. + def log_internal_error( err ) + log_internal(-2) { err } + raise err if Thread.abort_on_exception + end + # Close all appenders def shutdown( *args ) return unless initialized? log_internal {'shutdown called - closing all appenders'} ::Logging::Appenders.each {|appender| appender.close} @@ -524,26 +476,25 @@ const_defined? :MAX_LEVEL_LENGTH end # :startdoc: end + require libpath('logging/version') require libpath('logging/appender') require libpath('logging/layout') + require libpath('logging/filter') require libpath('logging/log_event') require libpath('logging/logger') require libpath('logging/repository') require libpath('logging/root_logger') - require libpath('logging/stats') require libpath('logging/color_scheme') require libpath('logging/appenders') require libpath('logging/layouts') + require libpath('logging/filters') require libpath('logging/proxy') require libpath('logging/diagnostic_context') - require libpath('logging/config/configurator') - require libpath('logging/config/yaml_configurator') - require libpath('logging/rails_compat') end # module Logging # This finalizer will close all the appenders that exist in the system. @@ -552,8 +503,5 @@ # # You can prevent the finalizer from running by calling `exit!` from your # application. This is required when daemonizing. # ObjectSpace.define_finalizer self, Logging.method(:shutdown) - -end # unless defined? -