Class: Log4r::Outputter

### Home Classes Methods

### In Files

- lib/log4r/outputter/outputter.rb
- lib/log4r/outputter/outputterfactory.rb
- lib/log4r/outputter/staticoutputter.rb

### Parent

Monitor

### Methods

- ::[]
- ::[]=
- ::each
- ::each_outputter
- ::new
- ::stderr
- ::stdout
- #flush
- #formatter=
- #level=
- #only_at
- #validate_hash

### Files

- GDC
- MDC
- NDC
- configurator
- emailoutputter
- formatter
- log4jxmlformatter
- log4r
- logger
- logserver
- outputter
- patternformatter
- scribeoutputter
- syslogoutputter
- win32eventoutputter
- yamlconfigurator

### Class/Module Index

Quicksearch

- Log4r
- Log4r::BasicFormatter
- Log4r::ConfigError
- Log4r::Configurator
- Log4r::DateFileOutputter
- Log4r::DefaultFormatter
- Log4r::EmailOutputter
- Log4r::FileOutputter
- Log4r::Formatter
- Log4r::GDC
- Log4r::IOOutputter
- Log4r::Log4jXmlFormatter
- Log4r::Log4rTools
- Log4r::LogEvent
- Log4r::LogServer
- Log4r::Logger
- Log4r::MDC
- Log4r::NDC
- Log4r::ObjectFormatter
- Log4r::Outputter
- Log4r::PatternFormatter
- Log4r::RemoteOutputter
- Log4r::RollingFileOutputter
- Log4r::RootLogger
- Log4r::ScribeOutputter
- Log4r::SimpleFormatter
- Log4r::StderrOutputter
- Log4r::StdoutOutputter
- Log4r::SyslogOutputter
- Log4r::UDPOutputter
- Log4r::YamlConfigurator
- REXML
- Object

No matching classes.

# Log4r::Outputter

### Attributes

formatter[R]
level[R]
name[R]

### Public Class Methods

[](name) click to toggle source

Retrieve an outputter.

    # File lib/log4r/outputter/staticoutputter.rb, line 6
    def self.[](name)
    out = @@outputters[name]
      if out.nil?
        return case name
        when 'stdout' then StdoutOutputter.new 'stdout'
        when 'stderr' then StderrOutputter.new 'stderr'
        else nil end
      end
      out
    end

[]=(name, outputter) click to toggle source

Set an outputter.

    # File lib/log4r/outputter/staticoutputter.rb, line 19
    def self.[]=(name, outputter)
      @@outputters[name] = outputter
    end

each() click to toggle source

Yields each outputter's name and reference.

    # File lib/log4r/outputter/staticoutputter.rb, line 23
    def self.each
      @@outputters.each {|name, outputter| yield name, outputter}
    end

each_outputter() click to toggle source

    # File lib/log4r/outputter/staticoutputter.rb, line 26
    def self.each_outputter
      @@outputters.each_value {|outputter| yield outputter}
    end

new(_name, hash={}) click to toggle source

An Outputter needs a name. RootLogger will be loaded if not already done. The hash arguments are as follows:

`:level`

  Logger level. Optional, defaults to root level

`:formatter`

  A Formatter. Defaults to DefaultFormatter

    # File lib/log4r/outputter/outputter.rb, line 28
    def initialize(_name, hash={})
      super()
      if _name.nil?
        raise ArgumentError, "Bad arguments. Name and IO expected.", caller
      end
      @name = _name
      validate_hash(hash)
      @@outputters[@name] = self
    end

stderr() click to toggle source

    # File lib/log4r/outputter/staticoutputter.rb, line 17
    def self.stderr; Outputter['stderr'] end

stdout() click to toggle source

    # File lib/log4r/outputter/staticoutputter.rb, line 16
    def self.stdout; Outputter['stdout'] end

### Public Instance Methods

flush() click to toggle source

Call flush to force an outputter to write out any buffered log events. Similar to IO#flush, so use in a similar fashion.

    # File lib/log4r/outputter/outputter.rb, line 81
    def flush
    end

formatter=(_formatter) click to toggle source

Dynamically change the formatter. You can just specify a Class object and the formatter will invoke `new` or `instance` on it as appropriate.

    # File lib/log4r/outputter/outputter.rb, line 63
    def formatter=(_formatter)
      if _formatter.kind_of?(Formatter)
        @formatter = _formatter
      elsif _formatter.kind_of?(Class) and _formatter <= Formatter
        if _formatter.respond_to? :instance
          @formatter = _formatter.instance
        else
          @formatter = _formatter.new
        end
      else
        raise TypeError, "Argument was not a Formatter!", caller
      end
      Logger.log_internal {"Outputter '#{@name}' using #{@formatter.class}"}
    end

level=(_level) click to toggle source

dynamically change the level

    # File lib/log4r/outputter/outputter.rb, line 39
    def level=(_level)
      Log4rTools.validate_level(_level)
      @level = _level
      OutputterFactory.create_methods(self)
      Logger.log_internal {"Outputter '#{@name}' level is #{LNAMES[_level]}"}
    end

only_at(*levels) click to toggle source

Set the levels to log. All others will be ignored

    # File lib/log4r/outputter/outputter.rb, line 47
    def only_at(*levels)
      raise ArgumentError, "Gimme some levels!", caller if levels.empty?
      raise ArgumentError, "Can't log only_at ALL", caller if levels.include? ALL
      levels.each {|level| Log4rTools.validate_level(level)}
      @level = levels.sort.first
      OutputterFactory.create_methods self, levels
      Logger.log_internal {
        "Outputter '#{@name}' writes only on " +         levels.collect{|l| LNAMES[l]}.join(", ")
      }
    end

### Protected Instance Methods

validate_hash(hash) click to toggle source

Validates the common hash arguments. For now, that would be `:level`, `:formatter` and the string equivalents

    # File lib/log4r/outputter/outputter.rb, line 90
    def validate_hash(hash)
      # default to root level and DefaultFormatter
      if hash.empty?
        self.level = Logger.root.level
        @formatter = DefaultFormatter.new
        return
      end
      self.level = (hash[:level] or hash['level'] or Logger.root.level)
      self.formatter = (hash[:formatter] or hash['formatter'] or DefaultFormatter.new)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.