lib/logging/config/yaml_configurator.rb in logging-0.6.2 vs lib/logging/config/yaml_configurator.rb in logging-0.6.3
- old
+ new
@@ -1,6 +1,6 @@
-# $Id: yaml_configurator.rb 77 2007-12-30 02:21:33Z tim_pease $
+# $Id: yaml_configurator.rb 88 2008-02-08 18:47:36Z tim_pease $
require 'yaml'
module Logging
module Config
@@ -13,47 +13,57 @@
class Error < StandardError; end # :nodoc:
class << self
# call-seq:
- # YamlConfigurator.load( file )
+ # YamlConfigurator.load( file, key = 'logging_config' )
#
# Load the given YAML _file_ and use it to configure the Logging
# framework. The file can be either a filename, and open File, or an
# IO object. If it is the latter two, the File / IO object will not be
# closed by this method.
#
- def load( file )
+ # The configuration will be loaded from the given _key_ in the YAML
+ # stream.
+ #
+ def load( file, key = 'logging_config' )
io, close = nil, false
case file
when String
io = File.open(file, 'r')
close = true
- when IO; io = file
- else raise Error, 'expecting a filename or a File' end
+ when IO
+ io = file
+ else
+ raise Error, 'expecting a filename or a File'
+ end
- begin new(io).load; ensure; io.close if close end
+ begin
+ new(io, key).load
+ ensure
+ io.close if close
+ end
nil
end
end # class << self
# call-seq:
- # YamlConfigurator.new( io )
+ # YamlConfigurator.new( io, key )
#
# Creates a new YAML configurator that will load the Logging
- # configuration from the given _io_ stream.
+ # configuration from the given _io_ stream. The configuration will be
+ # loaded from the given _key_ in the YAML stream.
#
- def initialize( io )
+ def initialize( io, key )
YAML.load_documents(io) do |doc|
- @config = doc['logging_config']
+ @config = doc[key]
break if @config.instance_of?(Hash)
end
unless @config.instance_of?(Hash)
- raise Error, "Key 'logging_config' not defined in YAML configuration"
+ raise Error, "Key '#{key}' not defined in YAML configuration"
end
end
- private :initialize
# call-seq:
# load
#
# Loads the Logging configuration from the data loaded from the YAML