Class: Logging::Config::Configurator

### Home Classes Methods

### In Files

- lib/logging/config/configurator.rb

### Parent

Object

### Namespace

- CLASS Logging::Config::Configurator::DSL
- CLASS Logging::Config::Configurator::Error
- CLASS Logging::Config::Configurator::TopLevelDSL

### Methods

- ::process
- #appender
- #appenders
- #layout
- #load
- #loggers
- #pre_config

### Files

- History.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Logging
- Logging::Appender
- Logging::Appenders
- Logging::Appenders::Buffering
- Logging::Appenders::Email
- Logging::Appenders::File
- Logging::Appenders::Growl
- Logging::Appenders::IO
- Logging::Appenders::RollingFile
- Logging::Appenders::Stderr
- Logging::Appenders::Stdout
- Logging::Appenders::StringIo
- Logging::Appenders::Syslog
- Logging::ColorScheme
- Logging::Config
- Logging::Config::Configurator
- Logging::Config::Configurator::DSL
- Logging::Config::Configurator::Error
- Logging::Config::Configurator::TopLevelDSL
- Logging::Config::YamlConfigurator
- Logging::Config::YamlConfigurator::Error
- Logging::Layout
- Logging::Layouts
- Logging::Layouts::Basic
- Logging::Layouts::Parseable
- Logging::Layouts::Pattern
- Logging::Logger
- Logging::MappedDiagnosticContext
- Logging::NestedDiagnosticContext
- Logging::Proxy
- Logging::RailsCompat
- Logging::Repository
- Logging::Repository::Singleton
- Logging::RootLogger
- Logging::Stats
- Logging::Stats::Sampler
- Logging::Stats::Tracker
- RSpec
- RSpec::Core
- RSpec::Core::Configuration
- RSpec::LoggingHelper
- RSpec::LoggingHelper
- Spec
- Spec::Runner
- Spec::Runner::Configuration
- Object
- Object::LoggingHelper
- File
- FileUtils
- Hash
- Kernel
- Module
- ReentrantMutex
- String

No matching classes.

# Logging::Config::Configurator

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.

### Public Class Methods

process( &block ) click to toggle source

    # File lib/logging/config/configurator.rb, line 15
    def self.process( &block )
      new.load(&block)
    end

### Public Instance Methods

appender( name, config ) click to toggle source

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
    def appender( name, config )
      type = config.delete(:type)
      raise Error, "appender type not given for #{name.inspect}" if type.nil?

      config[:layout] = layout(config[:layout]) if config.has_key? :layout

      clazz = ::Logging::Appenders.const_get type
      clazz.new(name, config)
    rescue NameError
      raise Error, "unknown appender class Logging::Appenders::#{type}"
    end

appenders( ary ) click to toggle source

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
    def appenders( ary )
      ary.each {|name, config| appender(name, config)}
    end

layout( config ) click to toggle source

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
    def layout( config )
      return ::Logging::Layouts::Basic.new if config.nil?

      type = config.delete(:type)
      raise Error, 'layout type not given' if type.nil?

      clazz = ::Logging::Layouts.const_get type
      clazz.new config
    rescue NameError
      raise Error, "unknown layout class Logging::Layouts::#{type}"
    end

load { block } click to toggle source

Loads the configuration from the block and configures the Logging gem.

    # File lib/logging/config/configurator.rb, line 25
    def load( &block )
      raise Error, "missing configuration block" unless block

      dsl = TopLevelDSL.new
      dsl.instance_eval(&block)

      pre_config dsl.__pre_config
      ::Logging::Logger[:root]  # ensures the log levels are defined
      appenders  dsl.__appenders
      loggers    dsl.__loggers
    end

loggers( ary ) click to toggle source

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
    def loggers( ary )
      ary.each do |name, config|
        l = Logging::Logger[name]
        l.level     = config[:level] if config[:level]
        l.additive  = config[:additive] if l.respond_to? :additive=
        l.trace     = config[:trace]
        l.appenders = Array(config[:appenders]).
                            map {|nm| ::Logging::Appenders[nm]}
      end
    end

pre_config( config ) click to toggle source

Configures the logging levels, object format style, and root logging level.

    # File lib/logging/config/configurator.rb, line 43
    def pre_config( config )
      if config.nil?
        ::Logging.init unless ::Logging.initialized?
        return
      end

      # define levels
      levels = config[:levels]
      ::Logging.init(levels) unless levels.nil?

      # format as
      format = config[:format_as]
      ::Logging.format_as(format) unless format.nil?

      # backtrace
      value = config[:backtrace]
      ::Logging.backtrace(value) unless value.nil?
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.