lib/logging.rb in logging-0.4.0 vs lib/logging.rb in logging-0.5.0
- old
+ new
@@ -1,14 +1,16 @@
-# $Id: logging.rb 35 2007-03-21 19:32:32Z tim_pease $
+# $Id: logging.rb 47 2007-11-13 05:14:55Z tim_pease $
require 'logging/repository'
# require all appenders
require 'logging/appenders/console'
require 'logging/appenders/file'
+require 'logging/appenders/growl'
require 'logging/appenders/rolling_file'
require 'logging/appenders/static_appender'
+require 'logging/appenders/syslog'
# require all layouts
require 'logging/layouts/basic'
require 'logging/layouts/pattern'
@@ -16,18 +18,19 @@
require 'logging/config/yaml_configurator'
#
#
-#
module Logging
+ VERSION = '0.5.0' # :nodoc:
+
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'
@@ -38,11 +41,10 @@
when '.yaml', '.yml':
::Logging::Config::YamlConfigurator.load(filename)
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
@@ -135,11 +137,10 @@
end
logger
end
- #
# call-seq:
# Logging.define_levels( 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
@@ -196,11 +197,10 @@
module_eval "MAX_LEVEL_LENGTH = #{longest.length}"
levels.keys
end
- #
# call-seq:
# Logging.format_as( obj_format )
#
# Defines the default _obj_format_ method to use when converting objects
# into string representations for logging. _obj_format_ can be one of
@@ -223,22 +223,40 @@
module_eval "OBJ_FORMAT = :#{f}"
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
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
case l
when 'all': 0
when 'off': LEVELS.length
else begin; Integer(l); rescue ArgumentError; LEVELS[l] end end
+ end
+
+ # Helper method for retrieving options from a hash.
+ def options( opts = {} )
+ lambda do |*args|
+ keys, default, ignored = args
+ catch('opt') do
+ Array(keys).each do |key|
+ [key, key.to_s, key.to_s.intern].each do |key|
+ throw 'opt', opts[key] if opts.has_key?(key)
+ end
+ end
+ default
+ end
+ end
end
# :startdoc:
end
end # module Logging