Parent

Log4r::Outputter

Attributes

name[R]

(Not documented)

level[R]

(Not documented)

formatter[R]

(Not documented)

Public Class Methods

[](name) click to toggle source

Retrieve an outputter.

# File 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 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 log4r/outputter/staticoutputter.rb, line 23
    def self.each
      @@outputters.each {|name, outputter| yield name, outputter}
    end
each_outputter() click to toggle source

(Not documented)

# File 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 log4r/outputter/outputter.rb, line 26
    def initialize(_name, hash={})
      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

(Not documented)

# File log4r/outputter/staticoutputter.rb, line 17
    def self.stderr; Outputter['stderr'] end
stdout() click to toggle source

(Not documented)

# File 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 log4r/outputter/outputter.rb, line 78
    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 log4r/outputter/outputter.rb, line 60
    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 log4r/outputter/outputter.rb, line 36
    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 log4r/outputter/outputter.rb, line 44
    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
validate_hash(hash) click to toggle source

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

# File log4r/outputter/outputter.rb, line 87
    def validate_hash(hash)
      @mutex = Mutex.new
      # 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

Private Instance Methods

canonical_log(logevent) click to toggle source

This method handles all log events passed to a typical Outputter. Overload this to change the overall behavior of an outputter. Make sure that the new behavior is thread safe.

# File log4r/outputter/outputter.rb, line 107
    def canonical_log(logevent)
      synch { write(format(logevent)) }
    end
format(logevent) click to toggle source

Common method to format data. All it does is call the resident formatter’s format method. If a different formatting behavior is needed, then overload this method.

# File log4r/outputter/outputter.rb, line 115
    def format(logevent)
      # @formatter is guaranteed to be DefaultFormatter if no Formatter
      # was specified
      @formatter.format(logevent)
    end
synch() click to toggle source

(Not documented)

# File log4r/outputter/outputter.rb, line 128
    def synch; @mutex.synchronize { yield } end
write(data) click to toggle source

Abstract method to actually write the data to a destination. Custom outputters should overload this to specify how the formatted data should be written and to where.

# File log4r/outputter/outputter.rb, line 125
    def write(data)
    end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.