Object
The Configurator class is used to configure the Logging framework using information found in a block of Ruby code. This block is evaluated in the context of the configurator’s DSL.
Creates a new Appender based on the given config options (a hash). The type of Appender created is determined by the ‘type’ option in the config. The remaining config options are passed to the Appender initializer.
The config options can also contain a ‘layout’ option. This should be another set of options used to create a Layout for this Appender.
# File lib/logging/config/configurator.rb, line 100 100: def appender( name, config ) 101: type = config.delete(:type) 102: raise Error, "appender type not given for #{name.inspect}" if type.nil? 103: 104: config[:layout] = layout(config[:layout]) if config.has_key? :layout 105: 106: clazz = ::Logging::Appenders.const_get type 107: clazz.new(name, config) 108: rescue NameError 109: raise Error, "unknown appender class Logging::Appenders::#{type}" 110: end
Given an array of Appender configurations, this method will iterate over each and create the Appender(s).
# File lib/logging/config/configurator.rb, line 68 68: def appenders( ary ) 69: ary.each {|name, config| appender(name, config)} 70: end
Creates a new Layout based on the given config options (a hash). The type of Layout created is determined by the ‘type’ option in the config. The remaining config options are passed to the Layout initializer.
# File lib/logging/config/configurator.rb, line 120 120: def layout( config ) 121: return ::Logging::Layouts::Basic.new if config.nil? 122: 123: type = config.delete(:type) 124: raise Error, 'layout type not given' if type.nil? 125: 126: clazz = ::Logging::Layouts.const_get type 127: clazz.new config 128: rescue NameError 129: raise Error, "unknown layout class Logging::Layouts::#{type}" 130: end
Loads the configuration from the block and configures the Logging gem.
# File lib/logging/config/configurator.rb, line 25 25: def load( &block ) 26: raise Error, "missing configuration block" unless block 27: 28: dsl = TopLevelDSL.new 29: dsl.instance_eval(&block) 30: 31: pre_config dsl.__pre_config 32: ::Logging::Logger[:root] # ensures the log levels are defined 33: appenders dsl.__appenders 34: loggers dsl.__loggers 35: end
Given an array of Logger configurations, this method will iterate over each and create the Logger(s).
# File lib/logging/config/configurator.rb, line 78 78: def loggers( ary ) 79: ary.each do |name, config| 80: l = Logging::Logger[name] 81: l.level = config[:level] if config[:level] 82: l.additive = config[:additive] if l.respond_to? :additive= 83: l.trace = config[:trace] 84: l.appenders = Array(config[:appenders]). 85: map {|nm| ::Logging::Appenders[nm]} 86: end 87: end
Configures the logging levels, object format style, and root logging level.
# File lib/logging/config/configurator.rb, line 43 43: def pre_config( config ) 44: if config.nil? 45: ::Logging.init unless ::Logging.initialized? 46: return 47: end 48: 49: # define levels 50: levels = config[:levels] 51: ::Logging.init(levels) unless levels.nil? 52: 53: # format as 54: format = config[:format_as] 55: ::Logging.format_as(format) unless format.nil? 56: 57: # backtrace 58: value = config[:backtrace] 59: ::Logging.backtrace(value) unless value.nil? 60: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.