Path: log4r/outputter/outputter.rb
Modified: Mon Aug 19 20:52:20 PDT 2002


An Outputter is a logging destination with a particular way to format data. It has a level threshold and a flexible level mask.

Outputters must have names.

Level Threshold

Outputters have their own level thresholds that default to root level. They will not write any log events with a rank less than their threshold.

Level Mask

Alternatively, an Outputter can be told to log specific levels only:

  o = 'console'
  o.only_at DEBUG, FATAL         # only DEBUG and FATAL get written

Outputter Repository

When outputters are created, they store themselves in an Outputter repository similar to the Logger repository. 'console'   => Create 'console' outputter
  Outputter['console']            => Get it back from the stash.


An outputter has a format defined by its Formatter. If no Formatter is specified, DefaultFormatter will be used.

Outputter is Abstract

The basic Outputter class is both abstract and a null object.

Useful Subclasses

Default Outputters

Two outputters named 'stdout' and 'stderr' are created automatically at the root level. They are nice shortcuts.

  Outputter['stdout'] => 'stdout'
  Outputter['stderr'] => 'stderr'
  Outputter.stdout    => 'stdout'
  Outputter.stderr    => 'stderr'


Outputters must have names and receive hash arguments. The parameter name for the hash args can be either a symbol or a string. All defined outputters accept :level and :formatter arguments. For arguments specific to a convenience Outputter, please look at the class description.

You can change the level threshold, levels logging (only_at), and formatter dynamically using the = methods.

Here are some ways to set up an IOOutputter: 'exotic', 'level' => WARN,
                  :formatter =>
  # an equivalent way:
  o = 'exotic'
  o.level = WARN
  o.formatter = MyFormatter         # we can specify just the class
  o.only_at = THIS, THAT

XML Configuration

Specify outputters as children of <log4r_config>:

    <outputter name="myout" type="Log4r::StdoutOutputter">
      <only_at>DEBUG, INFO</only_at>
    <outputter name="file" level="WARN">

As explained in log4r/configurator.rb, the hash arguments you would normally pass to new are specified as XML parameters. It is given an IO object to write to, a Formatter to call, and, optionally, levels to write at.

Outputters invoke print then flush on the wrapped IO object. If the IO chokes, the Outputter will close the IO and set its level to OFF.

Other Info

Version:$Id: outputter.rb,v 1.4 2002/08/20 03:52:20 cepheus Exp $
Author:Leon Torres <>
Required files

thread thread thread thread
Classes and Modules

Module Log4r
  ::Class Log4r::BasicFormatter
  ::Class Log4r::ConfigError
  ::Class Log4r::Configurator
  ::Class Log4r::DefaultFormatter
  ::Class Log4r::EmailOutputter
  ::Class Log4r::FileOutputter
  ::Class Log4r::Formatter
  ::Class Log4r::IOOutputter
  ::Class Log4r::Log4rTools
  ::Class Log4r::LogEvent
  ::Class Log4r::LogServer
  ::Class Log4r::Logger
  ::Class Log4r::ObjectFormatter
  ::Class Log4r::Outputter
  ::Class Log4r::PatternFormatter
  ::Class Log4r::RemoteOutputter
  ::Class Log4r::RollingFileOutputter
  ::Class Log4r::RootLogger
  ::Class Log4r::SimpleFormatter
  ::Class Log4r::StderrOutputter
  ::Class Log4r::StdoutOutputter