lib/logging.rb in logging-1.4.3 vs lib/logging.rb in logging-1.5.0
- old
+ new
@@ -1,16 +1,14 @@
# 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(
- File.join(File.dirname(__FILE__), %w[logging utils]))
+require File.expand_path('../logging/utils', __FILE__)
require 'yaml'
require 'stringio'
-require 'thread'
require 'fileutils'
require 'little-plugger'
HAVE_SYSLOG = require? 'syslog'
@@ -18,12 +16,12 @@
#
module Logging
extend LittlePlugger
# :stopdoc:
- LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
- PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
+ LIBPATH = ::File.expand_path('..', __FILE__) + ::File::SEPARATOR
+ PATH = ::File.expand_path('../..', __FILE__) + ::File::SEPARATOR
LEVELS = {}
LNAMES = []
module Plugins; end
# :startdoc:
@@ -159,10 +157,25 @@
#
def appenders
::Logging::Appenders
end
+ # Returns the color scheme identified by the given _name_. If there is no
+ # color scheme +nil+ is returned.
+ #
+ # If color scheme options are supplied then a new color scheme is created.
+ # Any existing color scheme with the given _name_ will be replaced by the
+ # new color scheme.
+ #
+ def color_scheme( name, opts = {} )
+ if opts.empty?
+ ::Logging::ColorScheme[name]
+ else
+ ::Logging::ColorScheme.new(name, opts)
+ end
+ end
+
# Reopen all appenders. This method should be called immediately after a
# fork to ensure no conflict with file descriptors and calls to fcntl or
# flock.
#
def reopen
@@ -288,11 +301,10 @@
longest = names.inject {|x,y| (x.length > y.length) ? x : y}
longest = 'off' if longest.length < 3
module_eval "MAX_LEVEL_LENGTH = #{longest.length}", __FILE__, __LINE__
initialize_plugins
-
levels.keys
end
# call-seq:
# Logging.format_as( obj_format )
@@ -466,11 +478,11 @@
else raise ArgumentError, "levels must be a String or Symbol" end
end
# Convert the given level into a level number.
def level_num( level )
- l = levelify level
+ l = levelify(level) rescue level
case l
when 'all'; 0
when 'off'; LEVELS.length
else begin; Integer(l); rescue ArgumentError; LEVELS[l] end end
end
@@ -488,10 +500,11 @@
# Reset the logging framework to it's uninitialized state
def reset
::Logging::Repository.reset
::Logging::Appenders.reset
+ ::Logging::ColorScheme.reset
LEVELS.clear
LNAMES.clear
remove_instance_variable :@backtrace if defined? @backtrace
remove_const :MAX_LEVEL_LENGTH if const_defined? :MAX_LEVEL_LENGTH
remove_const :OBJ_FORMAT if const_defined? :OBJ_FORMAT
@@ -507,12 +520,14 @@
require 'logging/log_event'
require 'logging/logger'
require 'logging/repository'
require 'logging/root_logger'
require 'logging/stats'
+ require 'logging/color_scheme'
require 'logging/appenders'
require 'logging/layouts'
+ require 'logging/proxy'
require 'logging/config/configurator'
require 'logging/config/yaml_configurator'
}
@@ -523,6 +538,5 @@
#
at_exit {Logging.shutdown}
end # unless defined?
-# EOF