Well, my code does seem to work, but I have the feeling that I could
have
done it much simpler.... So here is my problem:

I would like to control log4r via an environment variable, which can
contain one of 4 types of values:

  stdout         : logging goes to stdout
  stderr         : logging goes to stderr
  file:FILENAME  : logging goes to FILENAME
  none           : logging not needed

The problem is what outputter to use to implement 'none'. My first idea 
to simply use FileOutputter('none',:filename => '/dev/null') does not
work
because my code is also supposed to run onder Windows where we don't
have
/dev/null. So I came up with the solution to invent a "NullOutputter":

class NullOutputter <Outputter
  def initialize(name)
    super(name)
  end
end

....

$log = Logger.new('TestLog')
outputterspec=ENV['TFW_LOG'] || 'stdout'
$log.outputters = case outputterspec
  when 'stdout'
    Outputter.stdout
  when 'stderr'
    Outputter.stderr
  when /^file:(.+)$/
    FileOutputter.new 'tfw', :filename => $1, :trunc => true
  when 'none'
    NullOutputter.new 'tfwnull'  
  end

Note that I did NOT use

  when 'none'
    Outputter.new 'tfwnull'

because Outputter is documented as abstract class.

My solution works, but I wonder whether I could make it simpler 
(i.e. without creating the NullOutputter class).


Ronald
-- 
Ronald Fischer <ronald.fischer / venyon.com>
Phone: +49-89-452133-162