On 11/29/06, Damphyr <damphyr / freemail.gr> wrote:
> Can I have a Logger instance that logs both to a file and to STDOUT.
> Cheers,

Here's my tiny little modification to Logger that does that (though I
only do it when verbose is true):

require 'logger'
class TLogger < Logger
  attr_reader :logger
  def initialize(file, stdout, verbose=false)
    @logger = Logger.new(file)
    @logger.level = Logger::INFO
    @verbose = verbose
    @stdout = stdout
  end

  def log(str, lvl=:info)
    @logger.send(lvl, str)
    if lvl == :fatal
      raise str
    elsif (@verbose or !(lvl == :info))
      @stdout.puts(str) if (@verbose or !(lvl == :info))
    end
  end
end # of Class TLogger